Created
May 6, 2021 10:25
-
-
Save xinyii/4e750d70eee4b5dae37a99ce95a14471 to your computer and use it in GitHub Desktop.
[Scan all sub classes by ClassPathScanningCandidateComponentProvider] #spring
This file contains 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
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); | |
provider.addIncludeFilter(new AssignableTypeFilter(MyClass.class)); | |
// scan in org.example.package | |
Set<BeanDefinition> components = provider.findCandidateComponents("org.example.package"); | |
for (BeanDefinition component : components) { | |
Class cls = Class.forName(component.getBeanClassName()); | |
// use class cls found | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment