在eclipse中运行带有maven依赖项的spring boot应用程序时,我在启动时遇到以下异常:
java.lang.NoClassDefFoundError: org/springframework/web/context/support/GenericWebApplicationContext
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_92]
at java.lang.ClassLoader.defineClass(Unknown Source) ~[na:1.8.0_92]
at java.security.SecureClassLoader.defineClass(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader.defineClass(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader.access$100(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_92]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_92]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_92]
at java.lang.ClassLoader.defineClass(Unknown Source) ~[na:1.8.0_92]
at java.security.SecureClassLoader.defineClass(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader.defineClass(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader.access$100(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_92]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_92]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_92]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_92]
at java.lang.Class.forName(Unknown Source) ~[na:1.8.0_92]
at org.springframework.boot.SpringApplication.createApplicationContext(SpringApplication.java:574) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:325) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at co.hafiz.cm.launcher.Launcher.lambda$0(Launcher.java:33) [classes/:na]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.8.0_92]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_92]
Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.support.GenericWebApplicationContext
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_92]
... 32 common frames omitted
正如您所见,spring-web
可用,其中包含
org.springframework.web.context.support.GenericWebApplicationContext
会有什么问题?
答案 0 :(得分:2)
在我的Spring Boot项目中添加依赖spring-boot-starter-web解决了同样的错误。此外,您似乎在Spring Boot方面有很多不必要的依赖项。在Spring框架的情况下可能需要一些,但在Spring Boot中则不需要。
答案 1 :(得分:1)
您缺少spring框架,将其添加到您的依赖项
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>