SpringBoot异常: nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext解决方案

网友投稿 290 2023-01-02

SpringBoot异常: nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext解决方案

今天在使用SpringBoot创建了一个项目出现如下异常

org.springframework.beans.factory.Behttp://anCreationException: Error creating bean with name 'documentationPluginsBootstrapper': Resolution of declared constructors on bean Class [springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:281) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1129) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.supIEHBqbzKTport.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]

at com.zysh.server.web.ZyshWebApplication.main(ZyshWebApplication.java:12) [classes/:na]

Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext

at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_162]

at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[na:1.8.0_162]

at java.lang.Class.getDeclaredConstructors(Class.java:2020) ~[na:1.8.0_162]

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:276) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

... 17 common frames omitted

Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext

at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_162]

at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_162]

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_162]

at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_162]

上面很多都没有用只有一条

nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext

这里我交代一下,我不是使用的原版的父,而是自定义的。所以如果你是原版的也不会出现这个问题的。

这里其实很简单就是找不到这个类。我回头又看了下,其实不是找不到

这里一般常用的方法就是将pom.xml文件中的如下这个坐标的scope改为  runtime 就好

org.springframework.boot

spring-boot-starter-tomcat

provided

就像这样,这样我的程序就运行成功了。但是只是这样的话也没有必要记录了。

你点开你的pom文件中的【spring-boot-starter-web】你会清晰的看到这里已经引入了啊

所以你在pom文件中书写的tomcat的坐标完全就是多余的嘛,很简单删除这个坐标就好。

看不用修改scope了,程序完美运行。还有就是如果你要打war包的话,还需要将这个

【spring-boot-starter-tomcat】这个包给排除掉,为了以后少点麻烦这里还是不要改scope了直接删除就好。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:义乌优速快递物流查询单号(义乌优速快递服务电话)
下一篇:图片审核api接口网站(图片api搭建)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~