Scan for specific classes rather than just packages with classpath scanning
See original GitHub issueHi,
I would like to request for @EntityScan
to be able to provide the ability to scan for specific entities class, rather than based on package. E.g @EntityScan(classes={"com.aa.ClassA", "com.aa.ClassB"))
will only scan for these 2 classes and other classes in the same package will NOT be scan.
Searching internet shows many people asking for such capabilities and end up having to write some codes to circumvent this.
Adding such capabilities made life easy for developers
Likewise, should also provide similar way to configure this in properties/yaml as well.
E.g spring.jpa.entity-scan-classes=com.aa.ClassA,com.aa.ClassB
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Classpath Scanning using @ComponentScan and Filters
A Classpath scanning basically means, detecting the classes that need to be managed by the Spring under a specified package.
Read more >3.10 Classpath scanning and managed components - Spring
This section describes an option for implicitly detecting the candidate components by scanning the classpath. Candidate components are classes that match ...
Read more >EntityScan scan for specific classes rather than just packages
Hi,. I would like to request for @EntityScan to be able to provide the ability to scan for specific entities class, rather than...
Read more >spring - How to scan packages which are not in src/main/java?
Then you need to use @ComponentScan to scan for the relevant packages. Key thing here is to get your relevant code into the...
Read more >Spring Component Scanning - Baeldung
With Spring, we use the @ComponentScan annotation along with the @Configuration annotation to specify the packages that we want to be scanned.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not convinced that selecting individual entity classes (instead of scanning the package) is worthwhile, but I can foresee it being useful to be able to exclude particular classes based on a filter. That’s also what @wilkinsona suggested in https://github.com/spring-projects/spring-boot/issues/29193#issuecomment-1005667589.
Note that
@ComponentScan
already supportsexcludeFilters
.Even though i support the idea of exclude on filter, but why not make it more complete by also giving the ability to include only specific ones. To cater for a wide range of developers.