@ SafeVarargs public final Set < Class < ? > > scan ( Class < ? extends Annotation > ... annotationTypes ) throws ClassNotFoundException { List < String > packages = getPackages ( ) ; if ( packages . isEmpty ( ) ) { return Collections . emptySet ( ) ; } ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider ( false ) ; scanner . setEnvironment ( this . context . getEnvironment ( ) ) ; scanner . setResourceLoader ( this . context ) ; for ( Class < ? extends Annotation > annotationType : annotationTypes ) { scanner . addIncludeFilter ( new AnnotationTypeFilter ( annotationType ) ) ; } Set < Class < ? > > entitySet = new HashSet <> ( ) ; for ( String basePackage : packages ) { if ( StringUtils . hasText ( basePackage ) ) { for ( BeanDefinition candidate : scanner . findCandidateComponents ( basePackage ) ) { entitySet . add ( ClassUtils . forName ( candidate . getBeanClassName ( ) , this . context . getClassLoader ( ) ) ) ; } } } return entitySet ; }
Scan for entities with the specified annotations .