当前使用版本(必填,否则不予处理)
3.3.2 (maven central latest), master SNAPSHOT version has the same issue
该问题是如何引起的?(确定最新版也有问题再提!!!)
I'm not expert in mybatis and spring-boot-test, it maybe caused by dirty cache.
重现步骤(如果有就写完整)
Just modified the official sample project, see code at https://github.com/pan3793/mybatis-plus-samples/tree/2550/mybatis-plus-sample-quickstart
clone it and switch to branch 2550, change dir to mybatis-plus-sample-quickstart, then run mvn clean test -DskipTests=false, the issue should be reproduced.
报错信息
I only paste a snippet of full stacktrace, you can follow the steps to reproduce the error.
Caused by: org.apache.ibatis.builder.IncompleteElementException: Could not find result map 'com.baomidou.mybatisplus.samples.quickstart.mapper.UserMapper.mybatis-plus_User' referenced from 'com.baomidou.mybatisplus.samples.quickstart.mapper.UserMapper.selectById'
at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:341) ~[mybatis-3.5.4.jar:3.5.4]
at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:285) ~[mybatis-3.5.4.jar:3.5.4]
at com.baomidou.mybatisplus.core.injector.AbstractMethod.addMappedStatement(AbstractMethod.java:331) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at com.baomidou.mybatisplus.core.injector.AbstractMethod.addSelectMappedStatementForTable(AbstractMethod.java:270) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at com.baomidou.mybatisplus.core.injector.methods.SelectById.injectMappedStatement(SelectById.java:40) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at com.baomidou.mybatisplus.core.injector.AbstractMethod.inject(AbstractMethod.java:63) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at com.baomidou.mybatisplus.core.injector.AbstractSqlInjector.lambda$inspectInject$0(AbstractSqlInjector.java:55) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_201]
at com.baomidou.mybatisplus.core.injector.AbstractSqlInjector.inspectInject(AbstractSqlInjector.java:55) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder.parse(MybatisMapperAnnotationBuilder.java:122) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at com.baomidou.mybatisplus.core.MybatisMapperRegistry.addMapper(MybatisMapperRegistry.java:82) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at com.baomidou.mybatisplus.core.MybatisConfiguration.addMapper(MybatisConfiguration.java:103) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
at org.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:80) ~[mybatis-spring-2.0.4.jar:2.0.4]
... 66 common frames omitted
Comment From: nieqiurong
这个是在同一个jvm线程执行了两次SpringBootTest,容器初始化了两次,但mp的方法内部源码只使用了一个静态缓存来存储类对应的表信息(含mybatis的config对象),第一次执行完成之后,缓存了表信心相关,第二次执行的时候由于缓存了数据,只切换了config,没有重新初始化resultMap,导致了以上问题。
Comment From: pan3793
这个是在同一个jvm线程执行了两次SpringBootTest,容器初始化了两次,但mp的方法内部源码只使用了一个静态缓存来存储类对应的表信息(含mybatis的config对象),第一次执行完成之后,缓存了表信心相关,第二次执行的时候由于缓存了数据,只切换了config,没有重新初始化resultMap,导致了以上问题。
Thx for your explanation, have a plan to fix it or no plan to support it? Other spring boot official components seems work fine in this scenario.
Comment From: nieqiurong
使用3.3.3.2-SNAPSHOT试试。
Comment From: pan3793
使用3.3.3.2-SNAPSHOT试试。
Before I run my test, the unit test is broken.
CacheTest > testOrder() FAILED
org.opentest4j.AssertionFailedError at CacheTest.java:174
Comment From: pan3793
Confirm this bug has been fixed at 3.3.3.7-SNAPSHOT fd87b05. Thx.
Comment From: lijma
@pan3793 相同错误,还有更新吗, https://mvnrepository.com/artifact/com.baomidou/mybatis-plus 只支持到 3.3.2, 因为项目有多个integration test, 单独跑没问题, 放在一块就会失败。
Comment From: pan3793
@pan3793 相同错误,还有更新吗, https://mvnrepository.com/artifact/com.baomidou/mybatis-plus 只支持到 3.3.2, 因为项目有多个integration test, 单独跑没问题, 放在一块就会失败。
@nieqiurong Has plan to release 3.3.3?