Skip to content

Instantly share code, notes, and snippets.

@xinyii
Created May 6, 2021 10:25
Show Gist options
  • Save xinyii/4e750d70eee4b5dae37a99ce95a14471 to your computer and use it in GitHub Desktop.
Save xinyii/4e750d70eee4b5dae37a99ce95a14471 to your computer and use it in GitHub Desktop.
[Scan all sub classes by ClassPathScanningCandidateComponentProvider] #spring
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