Java 类org.springframework.core.type.filter.AnnotationTypeFilter 实例源码

项目:muon-java    文件:MuonRepositoryRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    Set<String> basePackages = getBasePackages(importingClassMetadata);
    ClassPathScanningCandidateComponentProvider scanner = getScanner();
    scanner.addIncludeFilter(new AnnotationTypeFilter(MuonRepository.class));
    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner
                .findCandidateComponents(basePackage);
        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {

                AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
                AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
                Assert.isTrue(annotationMetadata.isInterface(),
                        "@FeignClient can only be specified on an interface");

                BeanDefinitionHolder holder = createBeanDefinition(annotationMetadata);
                BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
            }
        }
    }

}
项目:tipi-engine    文件:AnnotationActivityRegistrar.java   
@Override
public void afterPropertiesSet() throws Exception {

    // on recherche toutes les classes concrètes du package à la recherche de celles qui sont annotées 'TipiTopProcess'
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false) {
        @Override
        protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
            return beanDefinition.getMetadata().isConcrete();
        }
    };
    scanner.addIncludeFilter(new AnnotationTypeFilter(TipiTopProcess.class));

    if (excludeFilters != null) {
        for (TypeFilter filter : excludeFilters) {
            scanner.addExcludeFilter(filter);
        }
    }

    Set<BeanDefinition> beans = scanner.findCandidateComponents(aPackage);
    LOGGER.info("Registering " + beans.size() + " Tipi activities");
    for (BeanDefinition bean : beans) {
        Class<?> clazz = Class.forName(bean.getBeanClassName());
        registerClass(clazz);
    }
}
项目:spring-data-documentdb    文件:DocumentDbConfigurationSupport.java   
protected Set<Class<?>> scanForEntities(String basePackage) throws ClassNotFoundException {
    if (!StringUtils.hasText(basePackage)) {
        return Collections.emptySet();
    }

    final Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();

    if (StringUtils.hasText(basePackage)) {
        final ClassPathScanningCandidateComponentProvider componentProvider =
                new ClassPathScanningCandidateComponentProvider(false);
        componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));

        for (final BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {

            initialEntitySet
                    .add(ClassUtils.forName(candidate.getBeanClassName(),
                            DocumentDbConfigurationSupport.class.getClassLoader()));
        }
    }

    return initialEntitySet;
}
项目:springboot-analysis    文件:ConsumerRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new AnnotationTypeFilter(Consumer.class));
    provider.addIncludeFilter(new AssignableTypeFilter(IConsumer.class));
    Set<BeanDefinition> beanDefinitionSet = provider.findCandidateComponents("spring.study.componentprovider.bean");

    for(BeanDefinition beanDefinition : beanDefinitionSet) {
        String beanName = beanNameGenerator.generateBeanName(beanDefinition, registry);
        if(!registry.containsBeanDefinition(beanName)) {
            registry.registerBeanDefinition(beanName, beanDefinition);
            registry.registerBeanDefinition("11", beanDefinition);
        }
    }

}
项目:lodsve-framework    文件:MongoBeanDefinitionRegistrar.java   
private static Set<String> getInititalEntityClasses(String[] domainPackages) {
    if (ArrayUtils.isEmpty(domainPackages)) {
        return null;
    }

    ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
    componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class));
    componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));

    Set<String> classes = new ManagedSet<>();
    for (String domainPackage : domainPackages) {
        if (StringUtils.isBlank(domainPackage)) {
            continue;
        }
        for (BeanDefinition candidate : componentProvider.findCandidateComponents(domainPackage)) {
            classes.add(candidate.getBeanClassName());
        }
    }

    return classes;
}
项目:schemagen-graphql    文件:GraphQLSpringSchemaBuilder.java   
public static List<IGraphQLTypeMapper> getDefaultTypeMappers() {
    ImmutableList.Builder<IGraphQLTypeMapper> builder = ImmutableList.builder();

    ClassPathScanningCandidateComponentProvider scanner =
            new ClassPathScanningCandidateComponentProvider(true);

    scanner.addIncludeFilter(new AnnotationTypeFilter(GraphQLTypeMapper.class));

    for (BeanDefinition bd : scanner.findCandidateComponents(IGraphQLTypeMapper.class.getPackage().getName())) {
        try {
            Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(),
                    ClassUtils.getDefaultClassLoader());

            builder.add((IGraphQLTypeMapper) cls.newInstance());
        } catch (Exception e) {
            LOGGER.error("Unexpected exception.", e);
        }
    }
    return builder.build();
}
项目:westcache    文件:WestCacheableClassPathScanner.java   
/**
 * Configures parent scanner to search for the right interfaces. It can search
 * for all interfaces or just for those that extends a markerInterface or/and
 * those annotated with the annotationClass
 */
public void registerFilters() {
    if (Envs.classExists("org.n3r.eql.eqler.annotations.Eqler")) {
        addExcludeFilter(new AnnotationTypeFilter(Eqler.class));
        addExcludeFilter(new AnnotationTypeFilter(EqlerConfig.class));
    }

    addIncludeFilter(new TypeFilter() {
        @Override
        public boolean match(MetadataReader metadataReader,
                             MetadataReaderFactory metadataReaderFactory
        ) throws IOException {
            val metadata = metadataReader.getClassMetadata();
            if (!metadata.isInterface()) return false;

            val className = metadata.getClassName();
            val clazz = Envs.forName(className);
            return Anns.isFastWestCacheAnnotated(clazz);
        }
    });

}
项目:spring4-understanding    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(7, beanCount);
    assertTrue(context.containsBean("messageBean"));
    assertFalse(context.containsBean("serviceInvocationCounter"));
    assertFalse(context.containsBean("fooServiceImpl"));
    assertFalse(context.containsBean("stubFooDao"));
    assertFalse(context.containsBean("myNamedComponent"));
    assertFalse(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
}
项目:spring4-understanding    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testCustomIncludeFilterAndDefaults() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
    scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(13, beanCount);
    assertTrue(context.containsBean("messageBean"));
    assertTrue(context.containsBean("serviceInvocationCounter"));
    assertTrue(context.containsBean("fooServiceImpl"));
    assertTrue(context.containsBean("stubFooDao"));
    assertTrue(context.containsBean("myNamedComponent"));
    assertTrue(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
}
项目:spring4-understanding    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testCustomAnnotationExcludeFilterAndDefaults() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
    scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(11, beanCount);
    assertFalse(context.containsBean("serviceInvocationCounter"));
    assertTrue(context.containsBean("fooServiceImpl"));
    assertTrue(context.containsBean("stubFooDao"));
    assertTrue(context.containsBean("myNamedComponent"));
    assertTrue(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
}
项目:spring4-understanding    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testMultipleCustomExcludeFiltersAndDefaults() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
    scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(10, beanCount);
    assertFalse(context.containsBean("fooServiceImpl"));
    assertFalse(context.containsBean("serviceInvocationCounter"));
    assertTrue(context.containsBean("stubFooDao"));
    assertTrue(context.containsBean("myNamedComponent"));
    assertTrue(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
}
项目:graviteeio-access-management    文件:AbstractRepositoryConfiguration.java   
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {

        String basePackage = getMappingBasePackage();
        Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();

        if (StringUtils.hasText(basePackage)) {
            ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(
                    false);
            componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class));
            componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));

            for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
                initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
                        this.getClass().getClassLoader()));
            }
        }

        return initialEntitySet;
    }
项目:spring-boot-square-oss-support    文件:RetrofitServiceFactoryBeanRegistrar.java   
/**
 * Scans for interfaces annotated with {@link RetrofitService} from the packages defined by
 * {@link RetrofitServiceScan}.
 *
 * @param annotationMetadata annotation metadata of the importing class
 * @param registry current bean definition registry
 */
private void doRegisterRetrofitServiceBeanDefinitions(
        AnnotationMetadata annotationMetadata,
        BeanDefinitionRegistry registry) {
    RetrofitServiceComponentProvider provider = new RetrofitServiceComponentProvider();
    provider.addIncludeFilter(new AnnotationTypeFilter(RetrofitService.class, true, true));

    // Find packages to scan for Retrofit services.
    Set<String> packagesToScan = getPackagesToScan(annotationMetadata);

    for (String packageToScan : packagesToScan) {
        logger.debug("Trying to find candidates from package {}", packageToScan);

        Set<BeanDefinition> candidates = provider.findCandidateComponents(packageToScan);

        if (!candidates.isEmpty()) {
            processCandidates(candidates, registry);
        }
    }
}
项目:distGatling    文件:JerseyConfig.java   
/**
* Scans for {@link javax.ws.rs.Path} annotated classes in the given packages and registers them with Jersey.
* @param controllerPackages Jersery controller base package names
*/
  protected void registerControllers(String[] controllerPackages) {
      ClassPathScanningCandidateComponentProvider scanner =
            new ClassPathScanningCandidateComponentProvider(false);
        scanner.addIncludeFilter(new AnnotationTypeFilter(javax.ws.rs.Path.class));

    for(String controllerPackage : controllerPackages) {
        logger.info("Scanning for Jersey controllers in '{}' package.", controllerPackage);

       for (BeanDefinition bd : scanner.findCandidateComponents(controllerPackage)) {
        logger.info("Registering Jersey endpoint class:  {}", bd.getBeanClassName());
        Class<?> controllerClazz = getJerseyControllerClass(bd.getBeanClassName());
        if(controllerClazz != null)
            register(controllerClazz);
       }
    }
  }
项目:distGatling    文件:JerseyConfig.java   
/**
* Scans for {@link javax.ws.rs.Path} annotated classes in the given packages and registers them with Jersey.
* @param controllerPackages Jersery controller base package names
*/
  protected void registerControllers(String[] controllerPackages) {
      ClassPathScanningCandidateComponentProvider scanner =
            new ClassPathScanningCandidateComponentProvider(false);
        scanner.addIncludeFilter(new AnnotationTypeFilter(javax.ws.rs.Path.class));

    for(String controllerPackage : controllerPackages) {
        logger.info("Scanning for Jersey controllers in '{}' package.", controllerPackage);

       for (BeanDefinition bd : scanner.findCandidateComponents(controllerPackage)) {
        logger.info("Registering Jersey endpoint class:  {}", bd.getBeanClassName());
        Class<?> controllerClazz = getJerseyControllerClass(bd.getBeanClassName());
        if(controllerClazz != null)
            register(controllerClazz);
       }
    }
  }
项目:distGatling    文件:JerseyConfig.java   
/**
* Scans for {@link javax.ws.rs.Path} annotated classes in the given packages and registers them with Jersey.
* @param controllerPackages Jersery controller base package names
*/
  protected void registerControllers(String[] controllerPackages) {
      ClassPathScanningCandidateComponentProvider scanner =
            new ClassPathScanningCandidateComponentProvider(false);
        scanner.addIncludeFilter(new AnnotationTypeFilter(javax.ws.rs.Path.class));

    for(String controllerPackage : controllerPackages) {
        logger.info("Scanning for Jersey controllers in '{}' package.", controllerPackage);

       for (BeanDefinition bd : scanner.findCandidateComponents(controllerPackage)) {
        logger.info("Registering Jersey endpoint class:  {}", bd.getBeanClassName());
        Class<?> controllerClazz = getJerseyControllerClass(bd.getBeanClassName());
        if(controllerClazz != null)
            register(controllerClazz);
       }
    }
  }
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:FilterAnnotations.java   
@SuppressWarnings("unchecked")
private TypeFilter createTypeFilter(FilterType filterType, Class<?> filterClass) {
    switch (filterType) {
    case ANNOTATION:
        Assert.isAssignable(Annotation.class, filterClass,
                "An error occurred while processing a ANNOTATION type filter: ");
        return new AnnotationTypeFilter((Class<Annotation>) filterClass);
    case ASSIGNABLE_TYPE:
        return new AssignableTypeFilter(filterClass);
    case CUSTOM:
        Assert.isAssignable(TypeFilter.class, filterClass,
                "An error occurred while processing a CUSTOM type filter: ");
        return BeanUtils.instantiateClass(filterClass, TypeFilter.class);
    }
    throw new IllegalArgumentException(
            "Filter type not supported with Class value: " + filterType);
}
项目:ibole-microservice    文件:RpcAnnotation.java   
/**
* Scan{@link com.github.ibole.microservice.config.annotation.Reference} Annotation.
*/ 
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
    throws BeansException {
  if (StringUtils.isEmpty(annotationPackage)) {
    return;
  }
  if (beanFactory instanceof BeanDefinitionRegistry) {
    BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) beanFactory;
    ClassPathBeanDefinitionScanner scanner =
        new ClassPathBeanDefinitionScanner(beanDefinitionRegistry, true);
    AnnotationTypeFilter filter = new AnnotationTypeFilter(Reference.class);
    scanner.addIncludeFilter(filter);
    scanner.scan(annotationPackages);
  }

}
项目:restful-api-cxf-spring-java    文件:ConfigUtils.java   
public List<Class> findClass( Class annotation ) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(annotation));

    List<Class> classList = new ArrayList<Class>();

    for (BeanDefinition bd : scanner.findCandidateComponents(BASE_PACKAGE)) {

        try {
            classList.add(Class.forName(bd.getBeanClassName()));
        } catch (ClassNotFoundException e) {

            LOG.error("problème de déploiement du service associé au bean : " + bd.getBeanClassName());
        }
    }

    return classList;
}
项目:restful-api-cxf-spring-java    文件:ConfigTestUtils.java   
public List<Class> findClasses( Class annotation ) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(annotation));

    List<Class> classList = new ArrayList<Class>();

    for (BeanDefinition bd : scanner.findCandidateComponents(BASE_PACKAGE)) {

        try {
            classList.add(Class.forName(bd.getBeanClassName()));
        } catch (ClassNotFoundException e) {

            LOG.error("problème de déploiement du service associé au bean : " + bd.getBeanClassName());
        }
    }

    return classList;
}
项目:spring-graphql-common    文件:GraphQLSchemaDiscoverer.java   
public static Set<Class<?>> findSchemaClasses(final String basePackage) throws ClassNotFoundException {

    Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();

    if (StringUtils.hasText(basePackage)) {
        ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(
                false);
        componentProvider.addIncludeFilter(new AnnotationTypeFilter(GRAPH_QL_SCHEMA_ANNOTATION));

        for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
            initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
                    GraphQLSchemaDiscoverer.class.getClassLoader()));
        }
    }
    return initialEntitySet;
}
项目:warpdb    文件:ClassUtils.java   
/**
 * Scan @Entity classes in base packages.
 * 
 * @param basePackages
 *            base package names.
 * @return List of entity class.
 */
public static List<Class<?>> scanEntities(String... basePackages) {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
    List<Class<?>> classes = new ArrayList<>();
    for (String basePackage : basePackages) {
        Set<BeanDefinition> beans = provider.findCandidateComponents(basePackage);
        for (BeanDefinition bean : beans) {
            try {
                classes.add(Class.forName(bean.getBeanClassName()));
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return classes;
}
项目:spring-boot-concourse    文件:FilterAnnotations.java   
@SuppressWarnings("unchecked")
private TypeFilter createTypeFilter(FilterType filterType, Class<?> filterClass) {
    switch (filterType) {
    case ANNOTATION:
        Assert.isAssignable(Annotation.class, filterClass,
                "An error occurred while processing a ANNOTATION type filter: ");
        return new AnnotationTypeFilter((Class<Annotation>) filterClass);
    case ASSIGNABLE_TYPE:
        return new AssignableTypeFilter(filterClass);
    case CUSTOM:
        Assert.isAssignable(TypeFilter.class, filterClass,
                "An error occurred while processing a CUSTOM type filter: ");
        return BeanUtils.instantiateClass(filterClass, TypeFilter.class);
    }
    throw new IllegalArgumentException(
            "Filter type not supported with Class value: " + filterType);
}
项目:spring-boot-concourse    文件:MongoDataAutoConfiguration.java   
private Set<Class<?>> getInitialEntitySet(BeanFactory beanFactory)
        throws ClassNotFoundException {
    Set<Class<?>> entitySet = new HashSet<Class<?>>();
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);
    scanner.setEnvironment(this.environment);
    scanner.setResourceLoader(this.resourceLoader);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Document.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
    for (String basePackage : getMappingBasePackages(beanFactory)) {
        if (StringUtils.hasText(basePackage)) {
            for (BeanDefinition candidate : scanner
                    .findCandidateComponents(basePackage)) {
                entitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
                        this.classLoader));
            }
        }
    }
    return entitySet;
}
项目:contestparser    文件:MongoDataAutoConfiguration.java   
private Set<Class<?>> getInitialEntitySet(BeanFactory beanFactory)
        throws ClassNotFoundException {
    Set<Class<?>> entitySet = new HashSet<Class<?>>();
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);
    scanner.setEnvironment(this.environment);
    scanner.setResourceLoader(this.resourceLoader);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Document.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
    for (String basePackage : getMappingBasePackages(beanFactory)) {
        if (StringUtils.hasText(basePackage)) {
            for (BeanDefinition candidate : scanner
                    .findCandidateComponents(basePackage)) {
                entitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
                        this.classLoader));
            }
        }
    }
    return entitySet;
}
项目:pungwecms    文件:ModuleManagementService.java   
/**
 * Scans the classpath for classes with the <b>@Module</b> annotation
 *
 * @see Module @Module
 */
public void scan() {
    List<String> defaultEnabledModules = applicationContext.getBean("defaultEnabledModules", List.class);
    // Important to remove all missing modules first, so scanning the classpath is quicker
    removeMissingModules();
    // If we have enabled modules then we should not attempt to enable those in the config file...
    final boolean enabledModules = !getModuleConfigService().listEnabledModules().isEmpty();
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Module.class));
    Set<BeanDefinition> modules = scanner.findCandidateComponents("*");
    modules.forEach(b -> {
        try {
            Class c = Class.forName(b.getBeanClassName());
            getModuleConfigService().registerModule(c, c.getProtectionDomain().getCodeSource().getLocation());
        } catch (ClassNotFoundException e) {
            LOG.error("Could not load a module found on the class path, due to it's class not being found. This should never happen and usually means something is wrong with the environment", e);
        }
    });

    if (!enabledModules && defaultEnabledModules != null && !defaultEnabledModules.isEmpty()) {
        enable(defaultEnabledModules);
    }
}
项目:zstack    文件:InventoryIndexManagerImpl.java   
private void populateTriggerVOs() throws ClassNotFoundException {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AnnotationTypeFilter(TriggerIndex.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    for (String pkg : getBasePkgNames()) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) {
            Class<?> triggerVO = Class.forName(bd.getBeanClassName());
            if (!triggerVO.isAnnotationPresent(Entity.class)) {
                throw new IllegalArgumentException(String.format("Class[%s] is annotated by @TriggerIndex, but not annotated by @Entity",
                        triggerVO.getName()));
            }
            triggerVOs.add(triggerVO);
            popluateTriggerVONamesCascade(triggerVO);
        }
    }
}
项目:zstack    文件:ConfigurationManagerImpl.java   
private void generateApiMessageGroovyClass(StringBuilder sb, List<String> basePkgs) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(APIMessage.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIReply.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIEvent.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                //classToApiMessageGroovyClass(sb, clazz);
                classToApiMessageGroovyInformation(sb, clazz);
            } catch (ClassNotFoundException e) {
                logger.warn(String.format("Unable to generate groovy class for %s", bd.getBeanClassName()), e);
            }
        }
    }
}
项目:zstack    文件:ConfigurationManagerImpl.java   
private void generateInventoryPythonClass(StringBuilder sb, List<String> basePkgs) {
    List<String> inventoryPython = new ArrayList<>();
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(PythonClassInventory.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg).stream().sorted((bd1, bd2) -> {
            return bd1.getBeanClassName().compareTo(bd2.getBeanClassName());
        }).collect(Collectors.toList())) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                if (isPythonClassGenerated(clazz)) {
                    /* This class was generated as other's parent class */
                    continue;
                }
                inventoryPython.add(classToInventoryPythonClass(clazz));
            } catch (Exception e) {
                logger.warn(String.format("Unable to generate python class for %s", bd.getBeanClassName()), e);
            }
        }
    }

    for (String invstr : inventoryPython) {
        sb.append(invstr);
    }
}
项目:zstack    文件:Deployer.java   
private void scanDeployer() {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(AbstractDeployer.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(org.springframework.stereotype.Component.class));
    for (BeanDefinition bd : scanner.findCandidateComponents("org.zstack.test")) {
        try {
            Class<?> clazz = Class.forName(bd.getBeanClassName());
            AbstractDeployer d = (AbstractDeployer) clazz.newInstance();
            deployers.put(d.getSupportedDeployerClassType(), d);
            logger.debug(String.format("Scanned a deployer[%s] supporting %s", d.getClass().getName(), d.getSupportedDeployerClassType()));
        } catch (Exception e) {
            logger.warn(String.format("unable to create deployer[%s], it's probably there are some beans requried by deployer is not loaded, skip it. error message:\n%s", bd.getBeanClassName(), e.getMessage()));
        }

    }
}
项目:zstack    文件:InventoryFacadeImpl.java   
@Override
public boolean start() {
    try {
        ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
        scanner.addIncludeFilter(new AnnotationTypeFilter(Inventory.class));
        scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
        scanner.addExcludeFilter(new AnnotationTypeFilter(org.springframework.stereotype.Component.class));
        for (String pkg : getBasePkgNames()) {
            for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) {
                Class<?> inventoryClass = Class.forName(bd.getBeanClassName());
                Inventory invat = inventoryClass.getAnnotation(Inventory.class);
                Info info = new Info();
                info.inventory = invat;
                info.inventoryClass = inventoryClass;
                inventoryMapping.put(invat.mappingVOClass(), info);
            }
        }
    } catch (Exception e) {
        throw new CloudRuntimeException(e);
    }
    return true;
}
项目:spring-data-crate    文件:AbstractCrateConfiguration.java   
/**
 * Scans the mapping base package for classes annotated with {@link Table}.
 * 
 * @see #getMappingBasePackage()
 * @return
 * @throws ClassNotFoundException
 */
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {

    String basePackage = getMappingBasePackage();
    Set<Class<?>> initialEntitySet = new HashSet<>();

    if (hasText(basePackage)) {
        ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
        componentProvider.addIncludeFilter(new AnnotationTypeFilter(Table.class));
        componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));

        for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
            initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(), AbstractCrateConfiguration.class.getClassLoader()));
        }
    }

    return initialEntitySet;
}
项目:class-guard    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(5, beanCount);
    assertTrue(context.containsBean("messageBean"));
    assertFalse(context.containsBean("serviceInvocationCounter"));
    assertFalse(context.containsBean("fooServiceImpl"));
    assertFalse(context.containsBean("stubFooDao"));
    assertFalse(context.containsBean("myNamedComponent"));
    assertFalse(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
}
项目:class-guard    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testCustomIncludeFilterAndDefaults() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
    scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(11, beanCount);
    assertTrue(context.containsBean("messageBean"));
    assertTrue(context.containsBean("serviceInvocationCounter"));
    assertTrue(context.containsBean("fooServiceImpl"));
    assertTrue(context.containsBean("stubFooDao"));
    assertTrue(context.containsBean("myNamedComponent"));
    assertTrue(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
}
项目:class-guard    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testCustomAnnotationExcludeFilterAndDefaults() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
    scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(9, beanCount);
    assertFalse(context.containsBean("serviceInvocationCounter"));
    assertTrue(context.containsBean("fooServiceImpl"));
    assertTrue(context.containsBean("stubFooDao"));
    assertTrue(context.containsBean("myNamedComponent"));
    assertTrue(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
}
项目:class-guard    文件:ClassPathBeanDefinitionScannerTests.java   
@Test
public void testMultipleCustomExcludeFiltersAndDefaults() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
    scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(8, beanCount);
    assertFalse(context.containsBean("fooServiceImpl"));
    assertFalse(context.containsBean("serviceInvocationCounter"));
    assertTrue(context.containsBean("stubFooDao"));
    assertTrue(context.containsBean("myNamedComponent"));
    assertTrue(context.containsBean("myNamedDao"));
    assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
}
项目:Cheddar    文件:RestResourceConfig.java   
@Autowired
public RestResourceConfig(final ApplicationContext applicationContext) {
    property("contextConfig", applicationContext);
    scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.resetFilters(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Path.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(Provider.class));
    register(RequestContextFilter.class);
    register(MultiPartFeature.class);
    register(ObjectMapperProvider.class);
    register(JacksonFeature.class);
    registerResources("com.clicktravel.cheddar.rest.exception.mapper", "com.clicktravel.cheddar.server.http.filter",
            "com.clicktravel.cheddar.server.rest.resource.status", "com.clicktravel.services",
            "com.clicktravel.cheddar.rest.body.writer");
    property(ServerProperties.LOCATION_HEADER_RELATIVE_URI_RESOLUTION_DISABLED, true);
}
项目:TechnologyReadinessTool    文件:JaxRSBeanFactoryPostProcessor.java   
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    if (registry.containsBeanDefinition("restServer")) {
        BeanDefinition beanDefinition = registry.getBeanDefinition("restServer");
        ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
        scanner.addIncludeFilter(new AnnotationTypeFilter(Path.class));
        BeanNameGenerator nameGenerator = new AnnotationBeanNameGenerator();
        List<RuntimeBeanReference> beanNames = new ManagedList<>();
        for (BeanDefinition definition : scanner.findCandidateComponents("net.techreadiness")) {
            String beanName = nameGenerator.generateBeanName(definition, registry);
            beanNames.add(new RuntimeBeanReference(beanName));
        }
        beanNames.addAll((Collection<? extends RuntimeBeanReference>) beanDefinition.getPropertyValues()
                .getPropertyValue("serviceBeans").getValue());
        beanDefinition.getPropertyValues().add("serviceBeans", beanNames);
    }
}
项目:dubbo2.js    文件:DubboComponentScanRegistrar.java   
/**
 * Registers Beans whose classes was annotated {@link Service}
 *
 * @param packagesToScan The base packages to scan
 * @param registry       {@link BeanDefinitionRegistry}
 */
private void registerServiceBeans(Set<String> packagesToScan, BeanDefinitionRegistry registry) {

    DubboClassPathBeanDefinitionScanner dubboClassPathBeanDefinitionScanner =
            new DubboClassPathBeanDefinitionScanner(registry, environment, resourceLoader);

    dubboClassPathBeanDefinitionScanner.addIncludeFilter(new AnnotationTypeFilter(Service.class));

    for (String packageToScan : packagesToScan) {

        Set<BeanDefinitionHolder> beanDefinitionHolders = dubboClassPathBeanDefinitionScanner.doScan(packageToScan);

        for (BeanDefinitionHolder beanDefinitionHolder : beanDefinitionHolders) {
            registerServiceBean(beanDefinitionHolder, registry);
        }

        if (logger.isInfoEnabled()) {
            logger.info(beanDefinitionHolders.size() + " annotated @Service Components { " +
                    beanDefinitionHolders +
                    " } were scanned under package[" + packageToScan + "]");
        }
    }

}
项目:elasticactors    文件:ElasticActorsBootstrapper.java   
public void init() {
    // annotation configuration context
    applicationContext = new AnnotationConfigApplicationContext();
    // set the correct configurations
    // ensure the EA annotations are scanned
    applicationContext.addIncludeFilters(new AnnotationTypeFilter(ServiceActor.class));
    // generate correct names for ServiceActor annotated actors
    applicationContext.setBeanNameGenerator(new ActorAnnotationBeanNameGenerator());
    // find all the paths to scan
    applicationContext.scan(ScannerHelper.findBasePackagesOnClasspath(CONFIGURATION_BASEPACKAGE));
    // load em up
    applicationContext.refresh();
    // add shutdown hook
    Runtime.getRuntime().addShutdownHook(new Thread("SHUTDOWN-HOOK") {
        @Override
        public void run() {
            applicationContext.destroy();
        }
    }
    );
}