Skip to content

Instantly share code, notes, and snippets.

@eclecticlogic
Created November 19, 2013 20:04
Show Gist options
  • Save eclecticlogic/7551622 to your computer and use it in GitHub Desktop.
Save eclecticlogic/7551622 to your computer and use it in GitHub Desktop.
Scan classpath to get classes matching specific attributes (type, package, etc).
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