springboot2搭建工程时遇到的棘手问题

典型问题

引入的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.

排查步骤:

  1. spring-boot-starter-tomcat的源文件发下实际依赖的是9.0.27如下图:

在这里插入图片描述
2. spring-boot-dependencies 的定义也是9.0.27:

在这里插入图片描述

  1. 经过排查发现项目父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插件能帮我们一步步分析排除。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章