Skip to content

fix: exclude annotation types from mapper candidate components#1258

Open
seonwooj0810 wants to merge 1 commit into
mybatis:masterfrom
seonwooj0810:fix/issue-1032-scanner-excludes-annotations
Open

fix: exclude annotation types from mapper candidate components#1258
seonwooj0810 wants to merge 1 commit into
mybatis:masterfrom
seonwooj0810:fix/issue-1032-scanner-excludes-annotations

Conversation

@seonwooj0810

Copy link
Copy Markdown

Fixes #1032

Problem

ClassPathMapperScanner#isCandidateComponent accepted any independent interface:

return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent();

Annotation types (@interface) are interfaces at the bytecode level and report isInterface() == true / isIndependent() == true. So an annotation declared inside a scanned base package passed this check and was wrongly registered as a MapperFactoryBean, 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 on master (the annotation type bean definition scanMarkerAnnotation is 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=trueTests 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 current master; (5) reproduced the bug with a failing test before applying the fix.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClassPathMapperScanner scan annotations in the package path as CandidateComponent.

1 participant