question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scan for specific classes rather than just packages with classpath scanning

See original GitHub issue

Hi,

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:open
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sbrannencommented, Jan 7, 2022

In fact, I was also suggesting to be able to exclude scan for specific classess e.g @EntityScan(excludeClasses = "MyClass1"), so that all classes are scanned except for the listed ones.

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 supports excludeFilters.

0reactions
hannah23280commented, Nov 14, 2022

In fact, I was also suggesting to be able to exclude scan for specific classess e.g @EntityScan(excludeClasses = "MyClass1"), so that all classes are scanned except for the listed ones.

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 spring-projects/spring-boot#29193 (comment).

Note that @ComponentScan already supports excludeFilters.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found