[已解决]Spring Boot 3中 MyBatis-Plus 依赖兼容性问题:Invalid bean definition with name ‘xxxMapper‘
·
最近我在使用 Spring Boot 3.4.4 开发博客系统时,项目启动时报错:
问题
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'activitiesServiceImpl': Unsatisfied dependency expressed through field 'baseMapper': No qualifying bean of type 'com.jawn.blogger.mapper.ActivitiesMapper' available
该错误表明 Spring 容器无法注入 ActivitiesMapper,即 Mapper 接口未被正确识别为 Bean。
原因分析
项目中使用了以下依赖:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.7</version>
</dependency>
这个版本的 mybatis-plus-boot-starter 主要适用于 Spring Boot 2.x,与 Spring Boot 3.x 存在兼容性问题。Spring Boot 3.x 引入了 Jakarta EE 9,包名从 javax.* 变更为 jakarta.*,导致旧版本的依赖无法正常工作。在网上查找的资料都是更新这个依赖的版本,但是发现都没有起作用,后面翻阅官方网站的文档说明才发现已经有了更新。
解决方案
将依赖替换为专为 Spring Boot 3.x 设计的适配器:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
更多推荐


所有评论(0)