public static void scan ( final Class < ? extends Annotation > clas , final String [ ] basePackage , final AnnotationHandler handler ) { final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider ( false ) ; scanner . setResourceLoader ( new PathMatchingResourcePatternResolver ( Thread . currentThread ( ) . getContextClassLoader ( ) ) ) ; scanner . addIncludeFilter ( new AnnotationTypeFilter ( clas ) ) ; for ( final String pck : basePackage ) { for ( final BeanDefinition bd : scanner . findCandidateComponents ( pck ) ) { handler . handleAnnotationFound ( bd . getBeanClassName ( ) ) ; } } }
Utility method to scan the given package and handler for the annotation of the given class . Its uses the Spring annotation detector