springboot3X 整合高版本mybatisplus
springboot版本
mp的版本
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.7</version>
</dependency>
创建一个mapper接口
@Mapper
public interface AiChatMemoryMapper extends BaseMapper<AiChatMemory> {
}
运行报错
原因分析
springboot3版本之后,FactoryBeanRegistrySupport#getTypeForFactoryBeanFromAttributes方法已经变了,如果 factoryBeanObjectType 不是 ResolvableType 或 Class 类型会抛出 IllegalArgumentException 异常。
此时因为 factoryBeanObjectType 是 String 类型,不符合条件而抛出异常。
我项目中使用的mybatis-plus-boot-starter 版本是 3.5.7 但是mybatis-spring为2.1.2 版本已经不兼容了。
解决步骤
1、排除旧的mybatis-spring
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.7</version><exclusions><exclusion><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId></exclusion></exclusions>
</dependency>
2、引入mybatis-spring3.0.4
<dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>3.0.4</version>
</dependency>
记得要刷新maven