SpringBoot 出现 java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory 错误,解决记录。

问题描述:
原因:未知
症状:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘categoryController’: Unsatisfied dependency expressed through field ‘categoryService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘categoryServiceImpl’: Unsatisfied dependency expressed through field ‘categoryMapper’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘categoryMapper’ defined in file [D:\MyProgram\IntelliJ IDEA 2020.3.1\workspace\XXXXX\target\classes\org\XXX\persistence\CategoryMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory

重点关注:

 java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory

解决方案:
pom.xml添加mybatis-plus-extension依赖。
注意:版本号尽量与 mybatis-plus-boot-starter 的版本号一致

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-extension</artifactId>
            <version>3.3.2</version>
 </dependency>

如果添加后出现错误:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(Ljava/lang/CharSequence;)Z

可能是因为mybatis-plus版本过低的问题,将版本提升到 3.2.1 以上即可。

参考:1.https://gitee.com/baomidou/mybatis-plus/issues/ITB8U
2.https://blog.youkuaiyun.com/qq_36725466/article/details/99978451
3.https://blog.youkuaiyun.com/weixin_47885169/article/details/106163161

依据网上博客描述。此问题还有一种原因:
同时引入了mybatis-plus-boot-starter 和 mybatis-spring-boot-starter 依赖。解决方法时将其中一个注释掉。

参考:https://my.oschina.net/sprouting/blog/3061346
https://www.cnblogs.com/jasongrass/p/13095486.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值