低版本idea中SpringBoot項(xiàng)目啟動(dòng)失敗后提示找不到j(luò)avax/servlet/ServletContext類該怎么解決

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)低版本idea中SpringBoot項(xiàng)目啟動(dòng)失敗后提示找不到 javax/servlet/ServletContext類該怎么解決,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

創(chuàng)新互聯(lián)公司主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、成都響應(yīng)式網(wǎng)站建設(shè)、程序開發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、微信小程序定制開發(fā)等,憑借多年來(lái)在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都做網(wǎng)站、成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷經(jīng)驗(yàn),集策劃、開發(fā)、設(shè)計(jì)、營(yíng)銷、管理等多方位專業(yè)化運(yùn)作于一體。

今天新入職的小伙伴找我?guī)退磦€(gè)問(wèn)題,同樣的springboot工程,同樣都是用idea,在我們的電腦上啟動(dòng)正常,但是在他的電腦上就是不行,直接報(bào)錯(cuò):java.lang.NoClassDefFoundError: javax/servlet/ServletContext,開始以為是沒(méi)編譯好,但是重新編譯之后依舊不行。

詳細(xì)錯(cuò)誤信息如下:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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:\我的文件\開發(fā)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

在網(wǎng)上查了一下,看到很多人提到pom文件中的jar包scope作用域問(wèn)題,將scope設(shè)置為provided時(shí),在打包時(shí)是不會(huì)被打進(jìn)去的,而我們的工程中,由于要使用外部tomcat容器,所以屏蔽掉了springboot內(nèi)嵌的tomcat。

低版本idea中SpringBoot項(xiàng)目啟動(dòng)失敗后提示找不到 javax/servlet/ServletContext類該怎么解決

但是當(dāng)時(shí)覺(jué)著跟這次的問(wèn)題不相關(guān),也就沒(méi)有怎么太在意,后來(lái),同事?lián)Q成eclipse之后,竟然把項(xiàng)目啟動(dòng)起來(lái)了。。。

看起來(lái)似乎是工具的問(wèn)題,我就順著這個(gè)方向繼續(xù)查原因,發(fā)現(xiàn)在idea的“Edit Configurations”菜單中是可以進(jìn)行設(shè)置maven的這個(gè)scope作用域的。

如下圖所示:

低版本idea中SpringBoot項(xiàng)目啟動(dòng)失敗后提示找不到 javax/servlet/ServletContext類該怎么解決

紅框所示之處,勾掉了之后,provided就不會(huì)生效了,運(yùn)行時(shí)就會(huì)找不到依賴的jar包。

我趕緊跑到同事電腦上一看,點(diǎn)開之后卻怎么都找不到上圖紅框中的設(shè)置,又是一番折騰,發(fā)現(xiàn)他的idea版本是2016,而我的是2020了。

上述就是小編為大家分享的低版本idea中SpringBoot項(xiàng)目啟動(dòng)失敗后提示找不到 javax/servlet/ServletContext類該怎么解決了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站標(biāo)題:低版本idea中SpringBoot項(xiàng)目啟動(dòng)失敗后提示找不到j(luò)avax/servlet/ServletContext類該怎么解決
URL網(wǎng)址:http://muchs.cn/article46/ghsjhg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)、Google、網(wǎng)站內(nèi)鏈、云服務(wù)器、網(wǎng)頁(yè)設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化

網(wǎng)站設(shè)計(jì)公司知識(shí)