-
-
Save jrichardsz/a34480c1bcc31c45da730c48c4f41331 to your computer and use it in GitHub Desktop.
Revisions
-
jrichardsz revised this gist
Dec 17, 2020 . 3 changed files with 33 additions and 32 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ import java.lang.annotation.Annotation; import java.util.LinkedList; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.web.context.support.StandardServletEnvironment; public class ClassScanner { private static final Logger logger = LoggerFactory.getLogger(ClassScanner.class); public static Class<?>[] findAllAnnotatedClassesInPackage(String packageName, Class<? extends Annotation> clazz) { final List<Class<?>> result = new LinkedList<Class<?>>(); final ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true, new StandardServletEnvironment()); provider.addIncludeFilter(new AnnotationTypeFilter(clazz)); for (BeanDefinition beanDefinition : provider.findCandidateComponents(packageName)) { try { result.add(Class.forName(beanDefinition.getBeanClassName())); } catch (ClassNotFoundException e) { logger.warn("Could not resolve class object for bean definition", e); } } return result.toArray(new Class<?>[result.size()]); } } 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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ Class<?>[] classes = ClassScanner .findAllAnnotatedClassesInPackage("org.acme.model.entities", Entity.class); -
skempken renamed this gist
Jan 20, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
skempken created this gist
Jan 20, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import java.util.LinkedList; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.context.annotation.Configuration; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.web.context.support.StandardServletEnvironment; public class Detector { private static final Logger LOGGER = LoggerFactory.getLogger(Detector.class); public Class<?>[] findAllConfigurationClassesInPackage(String packageName) { final List<Class<?>> result = new LinkedList<Class<?>>(); final ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( true, new StandardServletEnvironment()); provider.addIncludeFilter(new AnnotationTypeFilter(Configuration.class)); for (BeanDefinition beanDefinition : provider .findCandidateComponents(packageName)) { try { result.add(Class.forName(beanDefinition.getBeanClassName())); } catch (ClassNotFoundException e) { LOGGER.warn( "Could not resolve class object for bean definition", e); } } return result.toArray(new Class<?>[result.size()]); } }