Loading

[笔记] 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

posted @ 2020-06-11 19:17  J.晒太阳的猫  阅读(13339)  评论(1编辑  收藏  举报