首页   >   代码编程   >   JAVA开发

低版本idea中SpringBoot项目启动失败,提示找不到 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。

低版本idea中SpringBoot项目启动失败,提示找不到 javax/servlet/ServletContext类

但是当时觉着跟这次的问题不相关,也就没有怎么太在意,后来,同事换成eclipse之后,竟然把项目启动起来了。。。

看起来似乎是工具的问题,我就顺着这个方向继续查原因,发现在idea的“Edit Configurations”菜单中是可以进行设置maven的这个scope作用域的

如下图所示:

低版本idea中SpringBoot项目启动失败,提示找不到 javax/servlet/ServletContext类

红框所示之处,勾掉了之后,provided就不会生效了,运行时就会找不到依赖的jar包。

我赶紧跑到同事电脑上一看,点开之后却怎么都找不到上图红框中的设置,又是一番折腾,发现他的idea版本是2016,而我的是2020了。。。

雨落无影

QQ群Ⅰ: 686430774 (已满)

QQ群Ⅱ: 718410762

QQ群Ⅲ: 638620451 (已满)

QQ群Ⅳ: 474195684

QQ群Ⅴ: 463034360 (已满)

QQ群Ⅵ: 879266502

QQ群Ⅶ: 627786015 (已满)

工作5分钟,吹逼2小时: 855525339 (娱乐消遣,广告狗勿进)

如果文章有帮到你,可以考虑请博主喝杯咖啡!

分享到:

欢迎分享本文,转载请注明出处!

作者:不忘初心

发布时间:2020-07-22

永久地址:https://www.jiweichengzhu.com/article/322378a857194c1580693944eff9468f

评论