[筆記] Spring boot 整合mybatis報錯ClassNotFoundException: org.mybatis.logging.LoggerFactory


直接原因

以下兩個依賴會沖突,有了 mybatis-plus-boot-starter,就不需要 spring 自己的 mybatis-spring-boot-starter 了。

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
    </dependency>

    <!-- mybatis-plus-->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.1.0</version>
    </dependency>

直接刪除 mybatis-spring-boot-starter 的引用就OK。

Mybatis-Plus 從 3.0.7.1 更新到 3.1.0(Spring Boot 2.1.3.RELEASE)時啟動出現 java.lang.ClassNotFoundException: org.mybatis.logging.LoggerFactory · Issue #885 · baomidou/mybatis-plus

沒有找到 mybatis-spring-boot-starter 的依賴?

有趣的問題是,pom.xml 中沒有直接找到 mybatis-spring-boot-starter 的依賴,那么,很有可能是其它項目依賴了 mybatis-spring-boot-starter,把這個依賴帶了進來。

使用 mvn denpendecy:tree 就可以分析出來,是誰依賴了 mybatis-spring-boot-starter

比如,我這里的情況就是,另一個項目依賴了 mybatis-spring-boot-starter

怎么解?
使用 exclusion 排除掉就可以啦。
如果有多個包依賴了 mybatis-spring-boot-starter,都需要排除。

        <dependency>
            <groupId>com.xxx.xxx</groupId>
            <artifactId>xxx-open-api</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>mybatis-spring-boot-starter</artifactId>
                    <groupId>org.mybatis.spring.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>

如果是多工程的項目,使用 mvn dependency:tree 出現錯誤,可以參考這個:
[筆記] 多模塊 maven 工程中,mvn dependency:tree 分析,jar 包找不到的問題處理。

參考鏈接:

原文鏈接:
https://www.cnblogs.com/jasongrass/p/13095486.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM