Skip to content

mybatis 报错 ClassNotFoundException org.mybatis.logging.LoggerFactory

Published: at 19:17

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

分析,jar 包找不到的问题处理。

参考链接:


原文链接: https://blog.jgrass.cc/posts/mybatis-class-not-found-exception/

本作品采用 「署名 4.0 国际」 许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。