您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发
【原】低版本idea中SpringBoot项目启动失败,提示找不到 javax/servlet/ServletContext类
不忘初心 2020-07-22 围观() 评论() 点赞() 【JAVA开发】
简介:今天新入职的小伙伴找我帮他看个问题,同样的springboot工程,同样都是用idea,在我们的电脑上启动正常,但是在他的电脑上就是不行,直接报错:java.lang.NoClassDefFoundError: javax/servlet/ServletContext,开始以为是没编译好,但是重新编译之后依旧不行。
今天新入职的小伙伴找我帮他看个问题,同样的springboot工程,同样都是用idea,在我们的电脑上启动正常,但是在他的电脑上就是不行,直接报错:java.lang.NoClassDefFoundError: javax/servlet/ServletContext,开始以为是没编译好,但是重新编译之后依旧不行。
详细错误信息如下:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.3.RELEASE)
2020-07-13 17:32:02.265 [main] INFO com.sowin.frpx.FrpxApplication - Starting FrpxApplication on USERUQI-3VMPK83 with PID 9232 (started by Administrator in D:\我的文件\开发2\frpx)
2020-07-13 17:32:02.267 [main] DEBUG com.sowin.frpx.FrpxApplication - Running with Spring Boot v1.5.3.RELEASE, Spring v4.3.8.RELEASE
2020-07-13 17:32:02.267 [main] INFO com.sowin.frpx.FrpxApplication - The following profiles are active: dev
2020-07-13 17:32:02.434 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 5.3.5.Final
2020-07-13 17:32:02.462 [main] INFO o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@134d26af: startup date [Mon Jul 13 17:32:02 CST 2020]; root of context hierarchy
2020-07-13 17:32:02.838 [main] WARN o.s.c.a.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.sowin.frpx.FrpxApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
2020-07-13 17:32:02.840 [main] ERROR o.s.b.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@134d26af: startup date [Mon Jul 13 17:32:02 CST 2020]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.sowin.frpx.FrpxApplication.main(FrpxApplication.java:23)
2020-07-13 17:32:02.845 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.sowin.frpx.FrpxApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.sowin.frpx.FrpxApplication.main(FrpxApplication.java:23)
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163)
at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:380)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:314)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
... 12 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152)
... 17 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 21 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:57010', transport: 'socket'
Process finished with exit code 1
在网上查了一下,看到很多人提到pom文件中的jar包scope作用域问题,将scope设置为provided时,在打包时是不会被打进去的,而我们的工程中,由于要使用外部tomcat容器,所以屏蔽掉了springboot内嵌的tomcat。
但是当时觉着跟这次的问题不相关,也就没有怎么太在意,后来,同事换成eclipse之后,竟然把项目启动起来了。。。
看起来似乎是工具的问题,我就顺着这个方向继续查原因,发现在idea的“Edit Configurations”菜单中是可以进行设置maven的这个scope作用域的。
如下图所示:
红框所示之处,勾掉了之后,provided就不会生效了,运行时就会找不到依赖的jar包。
我赶紧跑到同事电脑上一看,点开之后却怎么都找不到上图红框中的设置,又是一番折腾,发现他的idea版本是2016,而我的是2020了。。。
看完文章,有任何疑问,请加入群聊一起交流!!!
很赞哦! ()
相关文章
- SpringBoot使用@Async注解导致循环依赖的原因及解决方案
- springboot配置双数据源报错“jdbcUrl is required with driverClassName”
- springboot整合jpa启动报错'hibernate.dialect' not set
- springboot使用jackson处理时间碰到的两个坑
- springboot项目提示“Failed to determine a suitable driver class”
- springboot打war包,部署到外部tomcat
- springboot项目在mac下启动特别慢
- 使用idea搭建springboot项目图文教程
- Spring Boot配置Druid数据源和使用教程
- springboot连接mysql报错“java.lang.IllegalArgumentException: HOUR_OF_DAY: 2 -> 3”
标签云
猜你喜欢
- IntelliJ IDEA 2019.2已经可以利用补丁永久破解激活了
- IntelliJ IDEA 2019.3利用补丁永久破解激活教程
- IntelliJ IDEA高版本最灵活的永久破解激活方法(含插件激活,时长你说了算)
- Jetbrains全家桶基于ja-netfilter的最新破解激活详细图文教程
- IntelliJ IDEA 2022.1永久破解激活教程(亲测可用,持续更新)
- 分享几个正版 IntelliJ IDEA 激活码(破解码、注册码),亲测可用,持续更新
- ja-netfilter到底需不需要mymap,2021.3.2版本激活失效?
- 如何激活idea2022.1及以上版本中的插件(亲测可用)
- 【史上最全】IntelliJ IDEA最新2022.1版本安装和激活视频教学(含插件)
- IntelliJ IDEA 2022.2 版本最新2099年永久激活方法,亲测可用,也可以开启新UI了。
站点信息
- 网站程序:spring + freemarker
- 主题模板:《今夕何夕》
- 文章统计:篇文章
- 标签管理:标签云
- 微信公众号:扫描二维码,关注我们