今天心血来潮,搭建一套项目,记录一下引入mybatis-plus导致的错误。
一:在pom文件中引入了mybatis-plus,但是并没有生效。也没有打印出mybatis-plus的logo。
出现了这样的一个错误:
Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.heqiang.springcloud.dao.DeptMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
引入的是:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.3.2</version>
</dependency>
实际上使用mybatis-plus是需要mybatis-plus-boot-starter的
修改为:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.2</version>
</dependency>
二:错误
Caused by: java.lang.ClassNotFoundException: org.mybatis.logging.LoggerFactory或者
com.baomidou.mybatisplus.core.MybatisConfiguration.getLanguageDriver(
原因是pom文件冲突了。应为mybatis-plus和mybatis以及pagehelper都会冲突。所以需要排查一下下
第一种,把pagehelper的mybatis排除,
第二种:删除mybatis-spring-boot-starter 的pom文件,直接使用mybatis-plus-boot-starter的mybatis,所以在mybatis-plus-boot-starter中不要排除mybatis。
第三种:直接在pom依赖树中查看什么地方使用到了mybatis,然后去进行排除
三:版本不兼容
直接去maven仓库去找到mybatis-plus的版本,然后看版本的兼容,比如3.3.2版本的mybatis-plus最低要求spring boot为2.3.0.RELEASE
maven仓库mybatis-plus地:https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter
四:在mapper层缺少@Mapper或者是启动类上面缺少@MapperSacn,二者有一个就可。