无法启动嵌入式 Tomcat NoClassDefFoundError DispatcherServletPath
Posted
技术标签:
【中文标题】无法启动嵌入式 Tomcat NoClassDefFoundError DispatcherServletPath【英文标题】:Unable to start embedded Tomcat NoClassDefFoundError DispatcherServletPath 【发布时间】:2019-02-04 07:41:03 【问题描述】:我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.qroom</groupId>
<artifactId>qroom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>qroom</name>
<description>qRoom Server</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>$spring-cloud.version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
当我启动我的应用程序时,我收到以下错误:
org.springframework.context.ApplicationContextException:无法启动网络服务器;嵌套异常是 org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 com.qroom.QroomApplication.main(QroomApplication.java:10) [classes/:na] 引起:org.springframework.boot.web.server.WebServerException:无法启动嵌入式Tomcat 在 org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:86) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:413) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] ...省略了8个常用框架 引起:org.springframework.beans.factory.BeanCreationException:在类路径资源[org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]中定义名称为“servletEndpointRegistrar”的bean创建错误:bean实例化通过工厂方法失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]:工厂方法“servletEndpointRegistrar”抛出异常;嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/web/servlet/DispatcherServletPath 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:226) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:214) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:91) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.servlet.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:80) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:250) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:237) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] 在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245) ~[tomcat-embed-core-8.5.32.jar:8.5.32] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.32.jar:8.5.32] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421) ~[tomcat-embed-core-8.5.32.jar:8.5.32] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411) ~[tomcat-embed-core-8.5.32.jar:8.5.32] 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_131] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_131] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_131] 在 java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_131] 原因:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]:工厂方法'servletEndpointRegistrar'抛出异常;嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/web/servlet/DispatcherServletPath 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] ...省略了23个常用框架 引起:java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/web/servlet/DispatcherServletPath 在 org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.servletEndpointRegistrar(ServletEndpointManagementContextConfiguration.java:71) ~[spring-boot-actuator-autoconfigure-2.0.4.RELEASE.jar:2.0.4.RELEASE ] 在 org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$a6542fda.CGLIB$servletEndpointRegistrar$0() ~[spring-boot-actuator-autoconfigure-2.0.4.RELEASE.jar:2.0 .4.发布] 在 org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$a6542fda$$FastClassBySpringCGLIB$$dc5ad488.invoke() ~[spring-boot-actuator-autoconfigure-2.0.4.RELEASE。罐子:2.0.4.RELEASE] 在 org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] 在 org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$a6542fda.servletEndpointRegistrar() ~[spring-boot-actuator-autoconfigure-2.0.4.RELEASE.jar:2.0.4.发布] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] 在 java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] ...省略了24个常用框架 引起:java.lang.ClassNotFoundException:org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath 在 java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131] 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131] 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_131] 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131] ...省略了 35 个常用框架
嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/web/servlet/DispatcherServletPath 我发现,问题出在 spring-cloud-starter-oauth2 依赖。如果我删除它,一切正常。我该如何解决这个问题?
【问题讨论】:
对于初学者,请停止混合同一框架的版本(2.0.4 和 2.0.2)。要覆盖休眠版本,请将<hibernate.version>5.3.5.Final</hibernate.version>
添加到 <properties>
元素并删除 hibernate
依赖项。 注意: DispatcherServletPath
是在 Spring Boot 2.0.4 中添加的,因此您的版本不匹配可能是此问题的根本原因。
@M.Deinum?非常感谢,对我有帮助
【参考方案1】:
M. Deinum 的评论帮助我解决了问题
对于初学者,请停止混合同一框架的版本(2.0.4 和 2.0.2)。要覆盖休眠版本,请将 5.3.5.Final 添加到元素并删除休眠依赖项。注意:DispatcherServletPath 是在 Spring Boot 2.0.4 中添加的,因此您的版本不匹配可能是此问题的根本原因
【讨论】:
【参考方案2】:如果你不使用dependencyManagement
,Maven 无法解决没有版本的依赖。为org.springframework.cloud
添加版本标签
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
【讨论】:
这不是真的。在pom.xml
中使用 dependencyManagement
部分时,您可以声明所需的依赖项。 Spring Boot 在其父级中提供了该功能,因此您可以省略该版本。这同样适用于提供一致版本控制的所谓 BOM(物料清单)依赖项。
没有看到dependencyManagement,感谢指正。以上是关于无法启动嵌入式 Tomcat NoClassDefFoundError DispatcherServletPath的主要内容,如果未能解决你的问题,请参考以下文章
无法启动嵌入式 Tomcat NoClassDefFoundError DispatcherServletPath
无法在 Spring Boot 中启动嵌入式 Tomcat [重复]
运行 Eureka Server 时无法启动嵌入式 Tomcat
将 Spring Boot 战争部署到 Tomcat 服务器并收到“无法启动嵌入式 Tomcat org.springframework.context.ApplicationContextExcep