gpt4 book ai didi

java - Maven项目在eclipse中抛出ClassNotFoundException

转载 作者:行者123 更新时间:2023-12-01 21:09:11 24 4
gpt4 key购买 nike

当在 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

在 Eclipse 的 Maven 依赖项中我得到: enter image description here

如您所见spring-web可用其中包含 org.springframework.web.context.support.GenericWebApplicationContext会出现什么问题?

最佳答案

在我的 Spring Boot 项目中添加依赖项 spring-boot-starter-web 解决了同样的错误。另外,您似乎对 Spring Boot 有很多不必要的依赖项。在 Spring 框架中可能需要一些,但在 Spring Boot 中则不需要。

关于java - Maven项目在eclipse中抛出ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41542159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com