GH-4103 - Use TypeScanner to scan for initial entities. - #5231
Open
masiljangajji wants to merge 3 commits into
Open
GH-4103 - Use TypeScanner to scan for initial entities.#5231masiljangajji wants to merge 3 commits into
masiljangajji wants to merge 3 commits into
Conversation
Replace the manual ClassPathScanningCandidateComponentProvider loop in MongoConfigurationSupport.scanForEntities(String) with the store-agnostic TypeScanner abstraction that was introduced along with the AOT support, following AbstractR2dbcConfiguration, JdbcConfiguration and CassandraEntityClassScanner. Scanning semantics are retained. Both paths disable default filters and match through AnnotationTypeFilter considering meta-annotations while excluding interfaces. Added a characterization test covering directly annotated types, meta-annotated types and annotated interfaces. It passes against the previous implementation as well as the new one. scanForEntities(String) is a protected extension point, so the throws ClassNotFoundException declaration is retained to keep overriding code source compatible. Class loading failures keep failing fast by rethrowing through onClassNotFound(…), as TypeScanner would otherwise silently drop types that cannot be loaded. Closes: spring-projects#4103 Signed-off-by: masiljangajji <xmfpdlsj0508@gmail.com>
Signed-off-by: masiljangajji <xmfpdlsj0508@gmail.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.
What
MongoConfigurationSupport.scanForEntities(String)scans entities using a manualClassPathScanningCandidateComponentProviderloop instead of the store-agnosticTypeScannerabstraction that sibling modules (AbstractR2dbcConfiguration,JdbcConfiguration,CassandraEntityClassScanner) already use.Why
#4103 tracks this:
TypeScannerwas introduced alongside Spring Data's AOT support specifically to avoid store-specific scanning implementations, and mongodb hadn't been migrated. Sibling modules already made the switch; mongodb was the one left behind.Fix
Replaced the manual loop with
TypeScanner.typeScanner(...).forTypesAnnotatedWith(Document.class).onClassNotFound(...).scanPackages(basePackage).collectAsSet(), matching the existing R2DBC/JDBC/Cassandra implementations — same shape asAbstractR2dbcConfiguration#scanForEntities.scanForEntities(String)is aprotectedextension point that has been part of the API since 1.10, so thethrows ClassNotFoundExceptiondeclaration stays to keep source compatibility for overriding code, even thoughTypeScanneritself doesn't throw a checked exception. Class loading failures still fail fast, rethrown throughonClassNotFound(...)— without itTypeScannersilently drops types it cannot load, which would be an observable behavior change. The exception type on that failure path does change fromClassNotFoundExceptiontoIllegalStateException, and the javadoc records that.Added a characterization test (
considersMetaAnnotatedTypesButNotInterfaces) covering directly annotated types, meta-annotated types, and annotated interfaces to confirm scanning semantics are unchanged; it passes against both the previous and the new implementation.MappingMongoConverterParser(the XML namespace parser) has the sameClassPathScanningCandidateComponentProviderusage in two places; I left it out to keep this change scoped to a single call site.This issue is assigned to @marcingrzejszczak, with no visible activity against it (comments, commits, PRs) in about 22 months. This change covers it.
Closes #4103