问题描述:
原因:未知
症状:
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