【MyBatis-Plus问题集】当我们使用MyBatis-Plus版本3.5.x时,会发现一直无法注册xxxMapper

项目场景

项目场景:我们想尝试新版本的MyBatis-Plus,使用目前比较新的版本3.5.3


问题描述

描述: 配置都确保正常且跟MyBatis-Plus官网配置一样后,启动项目时就会报错,无法找到xxxMapper,报错如下:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userMapper’ defined in file [D:\learnData\java_learning\project\cloudsurvey\target\classes\cn\itsource\code\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration’: Initialization of bean failed; nested exception is java.lang.TypeNotPresentException: Type com.baomidou.mybatisplus.extension.ddl.IDdl not present

解决方案

缺少依赖,在pom.xml文件添加下面依赖

<!--引入mybatis-plus依赖-->
<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus-extension</artifactId>
  <version>3.5.3</version>
</dependency>
<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus-boot-starter</artifactId>
  <version>3.5.3</version>
</dependency>