Created
November 19, 2013 20:04
-
-
Save eclecticlogic/7551622 to your computer and use it in GitHub Desktop.
Scan classpath to get classes matching specific attributes (type, package, etc).
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
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); | |
// Filter to include only classes that have a particular annotation. | |
provider.addIncludeFilter(new AnnotationTypeFilter(MyAnnotation.class)); | |
// Find classes in the given package (or subpackages) | |
Set<BeanDefinition> beans = provider.findCandidateComponents("com.xyz.abc"); | |
for (BeanDefinition bd : beans) { | |
// The BeanDefinition class gives access to the Class<?> and other attributes. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment