Description
MyBatis version
mybatis: 3.5.10
mybatis-spring-boot-starter: 2.2.2
org.mybatis:mybatis-spring:2.0.7
Database vendor and version
mysql 5.7.27
(But this issue is not related to mysql)
Test case or example project
It's a little difficult, so let me just report first.
If my explanation is confusing, I'll do my best to write a small sample code.
Steps to reproduce
In my application, I use mapper definition with annotation like below.
@Select("... ommited ...")
@Results(id = "someId", ... ommited ...)
fun select1(...): SomePojo?
@Select("... ommited ...")
@ResultMap("someId")
fun select2(...): SomePojo?
When loading this Mapper Interface, the order returned by Java Class.getMethods
is undefined, so incompleteMethods
occurs in this process.
https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java#L123-L136
Subsequent parsePendingMethods
resolve this incompleteMethods
.
https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java#L138
However, other mepper Interface methods may be executed at other threads before incompleteMethods
are resolved.
At this time, an error(IncompleteElementException
) will occur because incompleteMethods
exists.
https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/session/Configuration.java#L848-L853
https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/session/Configuration.java#L918-L925
Normally, all DI of spring is done in main thread.
However, if we prepare an instance that executes Mapper Interface in the background thread in DI processing, we will encounter the above problem.
Expected result
The method call of Mapper Interface succeeds without error.
Actual result
_