fix: exclude annotation types from mapper candidate components#1258
Open
seonwooj0810 wants to merge 1 commit into
Open
fix: exclude annotation types from mapper candidate components#1258seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
ClassPathMapperScanner#isCandidateComponent accepted any independent interface. Annotation types are interfaces at the bytecode level, so an annotation declared in a scanned package was treated as a mapper candidate and wrongly registered as a MapperFactoryBean. Exclude annotation metadata so only real mapper interfaces are scanned. Fixes mybatisgh-1032 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1032
Problem
ClassPathMapperScanner#isCandidateComponentaccepted any independent interface:Annotation types (
@interface) are interfaces at the bytecode level and reportisInterface() == true/isIndependent() == true. So an annotation declared inside a scanned base package passed this check and was wrongly registered as aMapperFactoryBean, as noted in #1032.Fix
Also require
!metadata.isAnnotation(), so annotation types are excluded while regular mapper interfaces in the same package continue to be scanned.Test evidence
Added
ClassPathMapperScannerAnnotationTest, which scans a package containing both a regular mapper interface and an annotation type, and asserts the mapper interface is registered while the annotation type is not. The test fails onmaster(the annotation type bean definitionscanMarkerAnnotationis present) and passes with this change.The supporting types live in a dedicated, otherwise-unscanned package (
org.mybatis.spring.scancandidate) so existing scanner tests are unaffected../mvnw test -Dlicense.skip=true—Tests run: 223, Failures: 0, Errors: 0, Skipped: 15(BUILD SUCCESS).Verification done: (1) no in-flight PR for the issue; (2) no claim comments on the thread; (3) code-focused change in
ClassPathMapperScanner.java; (4) confirmed the pattern still exists on currentmaster; (5) reproduced the bug with a failing test before applying the fix.