服务器之家

服务器之家 > 正文

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

时间:2021-09-17 10:32     来源/作者:馒头花卷儿

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

org.springframework.beans.factory.BeanCreationException: 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.support.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

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

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

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

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

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-tomcat</artifactId>
  4. <scope>provided</scope>
  5. </dependency>

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

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

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

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

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

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

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

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

到此这篇关于SpringBoot异常: nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext解决方案的文章就介绍到这了,更多相关SpringBoot解决nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/suxiexingchen/article/details/90719204

标签:

相关文章

热门资讯

yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
2021年耽改剧名单 2021要播出的59部耽改剧列表
2021年耽改剧名单 2021要播出的59部耽改剧列表 2021-03-05
返回顶部