SpringBoot 啟動失敗。又是
jar
沖突,這是第幾次了?
報錯細節
報錯細節:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1355)
The following method did not exist:
javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/opt/ETC/xxl-job-executor-etc/run/lib/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
jar:file:/opt/ETC/xxl-job-executor-etc/run/lib/tomcat-embed-core-9.0.41.jar!/javax/servlet/ServletContext.class
The class hierarchy was loaded from the following locations:
javax.servlet.ServletContext: file:/opt/ETC/xxl-job-executor-etc/run/lib/servlet-api-2.5.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
分析錯誤
描述信息大概意思是:你在調用一個不存在的方法,該方法可以在xxx位置找到。
what fk ?看到17行
、18行
瞬間反應過來,這個方法在兩個jar中都有,並且類路徑完全相同,jre懵逼了,不知道調用哪個,然后將問題拋出來給開發者:你必須讓我能夠明確知道調用哪個。
接下來事情就明確了,我們需要剔除多余的重復jar
,本次示例的沖突是servlet-api
,由於SpringBoot
默認是使用內嵌的tomcat
啟動,所以應該是其他的依賴中重復導入了這個依賴,直接進行排除就OK了。
怎么排出重復依賴?
-
第一步:檢查pom有沒有顯示的引入沖突的依賴,如果有,remove 它,基本沒問題了。
-
第二步:如果第一步沒有解決,那就是被其他的依賴導入了,下面就演示一下排出依賴的步驟(以下通過
IDEA
進行maven依賴排出)打開
pom.xml
(平時我們瀏覽、編輯都是在Text
模式下):切換到
Dependency Analyzer
模式下:搜索
servlet-api
:排出依賴:右擊選擇的依賴,選擇
Exclude
。切換到
Text
模式,成功排除了沖突依賴: