Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String
目录
一、问题
二、错误原因分析
三、可能原因
(一) Mapper 接口扫描配置错误
(二) 验证依赖版本
1. Spring Boot2
2. Spring Boot 3
(三) 清理项目缓存
一、问题
Invalid bean definition with name 'userMapper' defined in file [E:\my_project\idea\ww-ai-agent\target\classes\com\ww\wwaiagent\mapper\UserMapper.class]: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
二、错误原因分析
factoryBeanObjectType
是 Spring 中用于指定 FactoryBean 创建的对象类型的属性。错误信息表明,Spring 期望这个属性是一个类(Class),但实际得到的是字符串(String)。
三、可能原因
(一) Mapper 接口扫描配置错误
@MapperScan
或 XML 配置中指定的包路径不正确。
一般在启动类中需要配置MapperScan
(二) 验证依赖版本
使用与 Spring Boot 兼容的 MaBatis-Spring-Boot-Starter 版本
通过 MyBatis-Plus 官网可以看到
1. Spring Boot2
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.12</version>
</dependency>
2. Spring Boot 3
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>3.5.12</version>
</dependency>
不同的Spring Boot 版本有不同的引入方式(我就是这里引入错误)
(三) 清理项目缓存
消除可能的编译缓存问题