@Component
public class XTest implements InitializingBean {
@Autowired
private AMapper amapper;
// 此处如果同时引入BMapper就不会报错
// @Autowired
// private BMapper bmapper;
@Override
public void afterPropertiesSet() throws Exception {
final List<XXXVO> vos =
amapper.selectJoinList(XXXVO.class, wrapper);
}
}
报错信息
Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: mapper not find by class , add mapper and extends BaseMapper or MPJBaseMapper
at com.github.yulichang.toolkit.Asserts.hasTable(Asserts.java:14) ~[mybatis-plus-join-core-1.4.7.jar:na]
at com.github.yulichang.toolkit.support.ColumnCache.lambda$getListField$1(ColumnCache.java:31) ~[mybatis-plus-join-core-1.4.7.jar:na]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_202]
at com.github.yulichang.toolkit.support.ColumnCache.getListField(ColumnCache.java:29) ~[mybatis-plus-join-core-1.4.7.jar:na]
at com.github.yulichang.wrapper.interfaces.Query.selectAll(Query.java:164) ~[mybatis-plus-join-core-1.4.7.jar:na]
at com.github.yulichang.wrapper.MPJLambdaWrapper.selectAll(MPJLambdaWrapper.java:194) ~[mybatis-plus-join-core-1.4.7.jar:na]
当前使用版本
mybatis-plus-join-boot-starter 1.4.7
该问题是如何引起的?
1、定义两个Mapper继承MPJBaseMapper、两个实体类,分别对应两张表 2、将以上定义个mapper打包作为一个starter组件,并使用@Configuration配置,使用@MapperScan扫描 3、该starter组件配置使用spring.factories 4、使用该组件的地方,定义一个类,实现InitializingBean接口,@Autowired引入其中一个mapper,在afterPropertiesSet 中使用该mapper,调用selectJoinList方法
重现步骤
根据上面四个步骤代码如下: 1、定义mapper、实体类
2、定义配置类
3、spring.factories
4、引入该组件后定义类
报错信息
Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: mapper not find by class , add mapper and extends BaseMapper or MPJBaseMapper
at com.github.yulichang.toolkit.Asserts.hasTable(Asserts.java:14) ~[mybatis-plus-join-core-1.4.7.jar:na]
at com.github.yulichang.toolkit.support.ColumnCache.lambda$getListField$1(ColumnCache.java:31) ~[mybatis-plus-join-core-1.4.7.jar:na]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_202]
at com.github.yulichang.toolkit.support.ColumnCache.getListField(ColumnCache.java:29) ~[mybatis-plus-join-core-1.4.7.jar:na]
at com.github.yulichang.wrapper.interfaces.Query.selectAll(Query.java:164) ~[mybatis-plus-join-core-1.4.7.jar:na]
at com.github.yulichang.wrapper.MPJLambdaWrapper.selectAll(MPJLambdaWrapper.java:194) ~[mybatis-plus-join-core-1.4.7.jar:na]
补充说明
1、调试发现,当调用selectJoinList时,会调用到TableInfoHelper.getTableInfo(Class<?> clazz) 但是其内部缓存 TABLE_INFO_CACHE只有AMapper,并没有BMapper,而从Ioc容器中,BMapper是已经在容器中的。
2、如果不是在afterPropertiesSet使用,而是其他普通不在springboot生命周期函数中,就不会报这个问题,例如在CommandLineRunner接口中