典型問題
引入的jar並未按照pom中的定義來
現象
導致的問題
導致內置tomcat啓動時一直報如下異常:
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
排查步驟:
- spring-boot-starter-tomcat的源文件發下實際依賴的是9.0.27如下圖:
2. spring-boot-dependencies 的定義也是9.0.27:
-
經過排查發現項目父pom中也定義的有tomcat.version和spingboot 父pom中有衝突:導入jar依賴衝突
<properties> .... ... <tomcat.version>8.0.30</tomcat.version> </properties>
解決:刪掉本項目中父Pom中定義的 和springboot有衝突的properties;
總結:儘量不要和框架裏定義的properties相沖突如springboot中spring-boot-dependencies定義的properties;如果出現jar包衝突且點進去發現和定義的不一致,排查下是否有其他項目依賴覆蓋了期望的依賴;jar衝突引發各種奇葩問題但使用 idea 的maven helper插件能幫我們一步步分析排除。