Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.springframework.data.neo4j.config;
 
 import  org.springframework.beans.factory.config.BeanDefinition;
 import  org.springframework.beans.factory.support.ManagedSet;
 import  org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
 import  org.springframework.core.type.filter.AnnotationTypeFilter;

Author(s):
mh
Since:
23.02.14
public class BasePackageScanner {
    public static Set<StringscanBasePackage(String basePackage) {
        return scanBasePackages(basePackage.split(","));
    }
    public static Set<StringscanBasePackages(String...basePackages) {
        ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
//        componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
        componentProvider.addIncludeFilter(new AnnotationTypeFilter(NodeEntity.class));
        componentProvider.addIncludeFilter(new AnnotationTypeFilter(RelationshipEntity.class));
        Set<Stringclasses = new ManagedSet<String>();
        for (String basePackage : basePackages) {
            for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
                classes.add(candidate.getBeanClassName());
            }
        }
        return classes;
    }
    public static Set<? extends Class<?>> scanBasePackageForClasses(String...basePackagesthrows ClassNotFoundException {
        Set<Class<?>> classes = new HashSet<>();
        for (String basePackage : basePackages) {
            for (String className : scanBasePackage(basePackage)){
                classes.add(loadClass(className));
            }
        }
        return classes;
    }
    private static Class loadClass(String classNamethrows ClassNotFoundException {
        return Thread.currentThread().getContextClassLoader().loadClass(className);
    }
New to GrepCode? Check out our FAQ X