IncompleteElementException occurs temporarily when Spring Application starts
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.9k
- Forks
- 2.6k
- Avg merge
- 3d 4m
- Merged PRs (30d)
- 8
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
_
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with MapperAnnotationBuilder.java around incompleteMethods and parsePendingMethods, then inspect the referenced Configuration.java paths where pending elements trigger IncompleteElementException. Reproduce the startup race described between mapper loading and background-thread execution. Done means mapper method calls succeed during application startup without this exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100