✅ 问题定位:
使用的是:
- Spring Boot 3.4.8
- MyBatis Spring Boot Starter 2.2.2
但:
mybatis-spring-boot-starter:2.2.2
是为 Spring Boot 2.x 设计的,不支持 Spring Boot 3.x。
✅ 正确做法:
升级 MyBatis 到 Spring Boot 3.x 兼容版本,例如:
xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.4</version> <!-- ✅ 支持 Spring Boot 3.x -->
</dependency>
✅ 总结一句话:
Spring Boot 3.x 必须使用 MyBatis 3.x 版本,否则会出现 Bean 注入失败、Mapper 无法识别等问题。
✅ 建议:
修改 pom.xml
中的版本后,执行:
bash
mvn clean install
然后重新运行项目或测试类。