无法启动嵌入式Tomcat NoClassDefFoundError DispatcherServlet Path



Mypom.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:无法启动web服务器;嵌套异常为org.springframework.boot.web.server.WebServerException:无法启动嵌入式Tomcat位于org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplication context.java:155)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)~[spring-context-5.08.RELEASE.jar:5.0.8.RELEASE]位于org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplication context.java:140)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.boot.SpringApplication.run(SpringApplication.java:330)[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:com.qroom.QroomApplication.main(QroomApp.java:10)[classes/:na]由以下原因引起:org.springframework.boot.web.server.WebServer异常:无法启动嵌入式Tomcat位于org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:86)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServiceFactory.java:413)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServiceFactory.java:174)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplication context.java:179)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplication context.java:152)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]…省略了8个常用框架由以下原因引起:org.springframework.beans.factory.BeanCreationException:在类路径资源[org/springframework/boot/actuate/autoconfig/endpoint/web/ServerEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]中创建名为"servletEndpointRegistrar"的bean时出错:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.BeanInstanceException:未能实例化[org.springfframework.boot.ectuate.endpoint.web.ServletEndpointRegistration]:工厂方法"ServletEndpointRegistrar"引发异常;嵌套异常是java.lang.NoClassDefFoundError:org/springframework/boot/autoconfig/web/servlet/DispatcherServlet路径位于org.springframework.beans.factory.support.ConstructureResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)~[spring-beans-5.0.8.REASE.jar:5.0.8.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RRELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)~[spring-bans-5.08.RELEASE.jar:5.0.8.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)~[spring-bans-5.08.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.RRELEASE]位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RRELEASE]网址:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)~[spring-beans-5.0.8.RELEASE.jar:5.0.8.REASE]网址:org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)~[spring-beans-5.0.8.RELEASE.jar:5.0.8.REASE]位于org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializedrBeans.java:226)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializedrBeans.java:214)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitialize rBeans(ServletContextInitializerBeans.java:91)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.servlet.ServletContextInitializerBeans。(ServletContextInitializerBeans.java:80)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplication context.java:250)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplication context.java:237)~[spring-boot-2.0.4.REASE.jar:2.0.4.RELEASE]网址:org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54)~[spring-boot-2.0.4.REASE.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.FFutureTask.run(FutureTask.java:266)~[na:1.8.0_131]位于java.util.concurrent.ThreadPoolExecutiator.runWorker(ThreadPoolExecutiator.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.BeanInstanceException:未能实例化[org.springfframework.boot.ectuate.endpoint.web.ServletEndpointRegistration]:工厂方法"ServletEndpointRegistrar"引发异常;嵌套异常是java.lang.NoClassDefFoundError:org/springframework/boot/autoconfig/web/servlet/DispatcherServlet路径网址:org.springframework.beans.factory.support.SimpleInstantiationStrategy.instante(SimpleInstantiatonStrategy.java:185)~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RRELEASE]位于org.springframework.beans.factory.support.ConstructureResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)~[spring-beans-5.0.8.REASE.jar:5.0.8.RELEASE]…省略了23个常见帧引起原因:java.lang.NoClassDefFoundError:org/springframework/boot/autoconfig/web/servlet/DispatcherServlet路径位于org.springframework.boot.exactuate.autoconfig.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContext Configuration.servletEndpointRegistrar(ServletEndpointManagement ContextConfiguration.java:71)~[spring-boot-atuator-autoconfig-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.activate.autoconfig.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContext Configuration$$EnhancerBySpringCGLIB$$a6544fda.CGLIB$servletEndpointRegistrar$0()~[spring-boot-activator-autoconfig-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.boot.activate.autoconfig.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContext Configuration$$EnhancerBySpringCGLIB$$a6544fda$$FastClassBySpringCGLIB$$dc5ad488.invoke()~[spring-boot-activator-autoconfig-2.0.4.REASE.jar:2.0.4.RELEASE]位于org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)~[spring-core-5.08.RELEASE.jar:5.0.8.RELEASE]位于org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.cintercept(ConfigurationClassEnancer.java:361)~[spring-context-5.08.RELEASE.jar:5.0.8.RELEASE]网址:org.springframework.boot.activate.autoconfig.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContext Configuration$$EnhancerBySpringCGLIB$$a6544fda.servletEndpointRegistor()~[spring-boot-activator-autoconfig-2.0.4.REASE.jar:2.0.4.RELEASE]在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)~[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.ioke(Method.java:498)~[na:1.8.0_131]网址:org.springframework.beans.factory.support.SimpleInstantiationStrategy.instante(SimpleInstantiatonStrategy.java:154)~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RRELEASE]…省略了24个常用帧引起原因:java.lang.ClassNotFoundException:org.springframework.boot.autoconfig.web.servlet.DispatcherServlet路径位于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.mic.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/autoconfig/web/servlet/DispatcherServlet路径

我发现问题出在spring-cloud-starter-oauth2依赖项中。如果我删除它,一切都很好。我该如何解决这个问题?

M。Deinum的评论帮助我解决了的问题

对于初学者来说,停止混合同一框架的版本(2.0.4和2.0.2)。要覆盖hibernate版本,请在元素中添加5.3.5.Final并删除hibernate依赖项。注意:DispatcherServlet Path是在Spring Boot 2.0.4中添加的,因此您的版本不匹配可能是这个问题的根本原因

Maven在没有版本的情况下无法解决您的依赖关系,如果您不使用dependencyManagement。为org.springframework.cloud添加版本标签

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>

最新更新