版本:3.5.1 缓存A:
@Mapper
@CacheNamespace
public interface CacheA {
@Select("select 1 from dual")
int testA();
}
缓存B
@Mapper
@CacheNamespaceRef(CacheA.class)
public interface CacheB {
@Select("select 1 from dual")
int testB();
}
当mybatis.config.xml,一切正常。
<mappers>
<mapper class="cn.test.mybatis.CacheDao.CacheA"/>
<mapper class="cn.test.mybatis.CacheDao.CacheB"/>
</mappers>
当我尝试这样做时。
<mappers>
<mapper class="cn.test.mybatis.CacheDao.CacheB"/>
<mapper class="cn.test.mybatis.CacheDao.CacheA"/>
</mappers>
有一些错误。我在源代码中找到了答案。MapperBuilderAssistant.java:265
...
if (unresolvedCacheRef) {
throw new IncompleteElementException("Cache-ref not yet resolved");
}
...
我觉得顺序很重要。但是当我将sprintboot与mybatis一起使用时,我可以控制它们的顺序。