报错记录:SprintBoot---Unable to start embedded container; nested exception is java.lang……
生活随笔
收集整理的這篇文章主要介紹了
报错记录:SprintBoot---Unable to start embedded container; nested exception is java.lang……
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
報錯信息
練習一個SpringBoot的小例子后,報出以下錯誤:Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: org.apache.catalina.Context.addServletMapping(Ljava/lang/String;Ljava/lang/String;)V
具體報錯信息如下:
. ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v1.4.0.RELEASE)2021-04-20 20:15:33.923 INFO xxxx--- [ main] com.example.curd.CurdApplication : Starting CurdApplication on xxx with PID xxxx(F:\Code\curd\target\classes started by xxx in F:\Code\curd) 2021-04-20 20:15:33.926 INFO xxxx--- [ main] com.example.curd.CurdApplication : The following profiles are active: dev 2021-04-20 20:15:34.950 WARN xxxx--- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: org.apache.catalina.Context.addServletMapping(Ljava/lang/String;Ljava/lang/String;)V 2021-04-20 20:15:34.961 ERROR xxxx--- [ main] o.s.boot.SpringApplication : Application startup failedorg.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: org.apache.catalina.Context.addServletMapping(Ljava/lang/String;Ljava/lang/String;)Vat org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.6.jar:5.3.6]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at com.example.curd.CurdApplication.main(CurdApplication.java:13) [classes/:na] Caused by: java.lang.NoSuchMethodError: org.apache.catalina.Context.addServletMapping(Ljava/lang/String;Ljava/lang/String;)Vat org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.addDefaultServlet(TomcatEmbeddedServletContainerFactory.java:256) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.prepareContext(TomcatEmbeddedServletContainerFactory.java:212) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:175) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]... 8 common frames omittedProcess finished with exit code 1解決思路
猜想報錯原因
博主在報錯信息中發現spring-boot-1.4.0.RELEASE,但博主的SpringBoot是2.4.5,故猜想是否是因為spring版本沖突。
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.5</version><relativePath/> <!-- lookup parent from repository --></parent>驗證猜想
然后查看maven庫,發現在org.springframework.boot中存在兩個版本
此外,在pom.xml文件中顯示的依賴是spring-boot-1.4.0.RELEASE
于是修改pom.xml文件中的依賴版本號為2.4.5,成功運行!
幾點認識:
在差錯過程中,需要對比文章中的報錯信息,如果報錯信息不符,就沒必要去看了
有時靜下心來仔細看看報錯信息,可能自己也能解決
關于此類錯誤,有多位博主曾遇到過并給出了他們解決方案,整理如下:
總結
以上是生活随笔為你收集整理的报错记录:SprintBoot---Unable to start embedded container; nested exception is java.lang……的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql常用命令--入门
- 下一篇: 模拟Servlet