背景:
拥抱新技术,使用Springboot3.4.1搭建新项目时,接入 Mybatisplus时,一直提示 Bean 找不到,无法注入
报错:
Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
分析:
网上各种方法都试过了,
1、@MapperScan扫描,
2、配置mybaitsplus
mybatis-plus:
type-aliases-package: com.***.entity # 实体类包路径
3、springboot版本切换
等等
最后上官网看了下,发现Springboot3以上的版本引入的mybaitsplus的包是
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.9</version>
</dependency>
而我之前使用IDE默认引入的是
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.9</version>
</dependency>
这个坑踩了一天,一直试错,也视图通过debug找问题,还好想到官网应该有说明
解决
Springboot3以上版本接入Mybatisplus时需要引入的包为
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.9</version>
</dependency>
最好看看官网最新的包