当前位置: 首页>>代码示例>>Java>>正文


Java ClassPathScanningCandidateComponentProvider类代码示例

本文整理汇总了Java中org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider的典型用法代码示例。如果您正苦于以下问题:Java ClassPathScanningCandidateComponentProvider类的具体用法?Java ClassPathScanningCandidateComponentProvider怎么用?Java ClassPathScanningCandidateComponentProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClassPathScanningCandidateComponentProvider类属于org.springframework.context.annotation包,在下文中一共展示了ClassPathScanningCandidateComponentProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerBeanDefinitions

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
@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);
        }
    }

}
 
开发者ID:fangjian0423,项目名称:springboot-analysis,代码行数:17,代码来源:ConsumerRegistrar.java

示例2: afterPropertiesSet

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:shared-vd,项目名称:tipi-engine,代码行数:26,代码来源:AnnotationActivityRegistrar.java

示例3: registerBeanDefinitions

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
@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);
            }
        }
    }

}
 
开发者ID:muoncore,项目名称:muon-java,代码行数:24,代码来源:MuonRepositoryRegistrar.java

示例4: getClasses

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
/**
 * Retourne les classes d'une package
 *
 * @param packageName
 * @return
 * @throws Exception
 */
public static List<Class> getClasses(String packageName) {
    final List<Class> list = new ArrayList<>();

    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(Object.class));
    final Set<BeanDefinition> bds = scanner.findCandidateComponents(packageName);
    try {
        for (BeanDefinition bd : bds) {
            final Class<?> tc = Class.forName(bd.getBeanClassName());
            if (tc.getAnnotation(Entity.class) != null) {
                list.add(tc);
            }
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return list;
}
 
开发者ID:shared-vd,项目名称:tipi-engine,代码行数:26,代码来源:HibernateMetaDataHelper.java

示例5: testCompileExtendedServices

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
@Test
public void testCompileExtendedServices() throws Exception
{
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
    provider.addIncludeFilter(new AssignableTypeFilter(Extensible.class));

    Set<BeanDefinition> components = provider.findCandidateComponents("org/alfresco/*");
    Set<Class<? extends Extensible>> extensibles = new HashSet<>();
    for (BeanDefinition component : components)
    {
        @SuppressWarnings("unchecked")
        Class<? extends Extensible> extensibleClass = (Class<? extends Extensible>) Class.forName(component
                    .getBeanClassName());
        extensibles.add(extensibleClass);

    }
    compile(extensibles);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:AJExtensionsCompileTest.java

示例6: scanForEntities

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
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;
}
 
开发者ID:Microsoft,项目名称:spring-data-documentdb,代码行数:23,代码来源:DocumentDbConfigurationSupport.java

示例7: cronyxQuartzConverterPairs

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
public static <T> List<Pair<Class, T>> cronyxQuartzConverterPairs(Class<T> tClass) {

        List<Pair<Class, T>> results = new ArrayList<>();

        ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
        provider.addIncludeFilter(new AssignableTypeFilter(tClass));

        Set<BeanDefinition> components = provider.findCandidateComponents(PACKAGE);
        for (BeanDefinition component : components) {
            try {
                Class cls = Class.forName(component.getBeanClassName());
                Class<?> typeArgument = GenericTypeResolver.resolveTypeArgument(cls, tClass);
                results.add(new ImmutablePair<>(typeArgument, (T) cls.newInstance()));

            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                throw new CronyxException("Could not instantiate cronyxToQuartzConverters", e);
            }
        }
        return results;
    }
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:21,代码来源:ConfigUtil.java

示例8: buildCommandHandlersRegistry

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
public static Map<String, CommandHandler> buildCommandHandlersRegistry(final String basePackage,
                                                                       final ApplicationContext context) {

    final Map<String, CommandHandler> registry = new HashMap<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
    scanner.addIncludeFilter(new AssignableTypeFilter(CommandHandler.class));

    CommandHandler currentHandler = null;

    for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) {
        currentHandler = (CommandHandler) beanFactory.createBean(ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()),
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
        registry.put(currentHandler.getInterest(), currentHandler);
    }

    return registry;
}
 
开发者ID:sem2nawara,项目名称:cqrs-es-kafka,代码行数:19,代码来源:CommandHandlerUtils.java

示例9: getInititalEntityClasses

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
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;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:22,代码来源:MongoBeanDefinitionRegistrar.java

示例10: getDefaultTypeMappers

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
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();
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:21,代码来源:GraphQLSpringSchemaBuilder.java

示例11: CachedSpringClassHierarchySupplier

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
public CachedSpringClassHierarchySupplier(Class<?> baseClass, String basePackage) {
  if (!baseClassSubClassesCache.containsKey(baseClass)) {
    ClassPathScanningCandidateComponentProvider provider =
        new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new AssignableTypeFilter(baseClass));

    Set<Class<?>> subClasses = new HashSet<>();
    for (BeanDefinition beanDefinition : provider.findCandidateComponents(basePackage)) {
      try {
        subClasses.add(Class.forName(beanDefinition.getBeanClassName()));
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException(
            String.format("Could not load child class '%s'.", beanDefinition.getBeanClassName()),
            e);
      }
    }
    baseClassSubClassesCache.put(baseClass, subClasses);
  }
  subClasses = baseClassSubClassesCache.get(baseClass);
}
 
开发者ID:coveo,项目名称:feign-error-decoder,代码行数:21,代码来源:CachedSpringClassHierarchySupplier.java

示例12: getSubClasses

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
@Override
public Set<Class<?>> getSubClasses(Class<?> clazz, String basePackage) {
  ClassPathScanningCandidateComponentProvider provider =
      new ClassPathScanningCandidateComponentProvider(false);
  provider.addIncludeFilter(new AssignableTypeFilter(clazz));

  Set<BeanDefinition> components = provider.findCandidateComponents(basePackage);

  return components
      .stream()
      .map(
          component -> {
            try {
              return Class.forName(component.getBeanClassName());
            } catch (ClassNotFoundException e) {
              throw new IllegalStateException(
                  String.format("Could not load child class '%s'.", component.getBeanClassName()),
                  e);
            }
          })
      .collect(Collectors.toSet());
}
 
开发者ID:coveo,项目名称:feign-error-decoder,代码行数:23,代码来源:SpringClassHierarchySupplier.java

示例13: scanPlugins

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
/**
 * List all official ES plugins available on ClassPath.
 * @return List of plugins class
 */
@SuppressWarnings("unchecked")
private static Collection<Class<? extends Plugin>> scanPlugins() {
	ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
	componentProvider.addIncludeFilter(new AssignableTypeFilter(Plugin.class));

	return componentProvider.findCandidateComponents("org.elasticsearch.plugin").stream()
			.map(BeanDefinition::getBeanClassName)
			.map(name -> {
				try {
					return (Class<? extends Plugin>) Class.forName(name);
				} catch (ClassNotFoundException e) {
					logger.warn("Cannot load class on plugin detection", e);
					return null;
				}
			})
			.collect(Collectors.toSet());
}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:22,代码来源:ElasticsearchJestAutoConfiguration.java

示例14: getInitialEntitySet

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
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;
    }
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:20,代码来源:AbstractRepositoryConfiguration.java

示例15: buildCommandHandlersRegistry

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入依赖的package包/类
public static Map<String, CommandHandler> buildCommandHandlersRegistry(final String basePackage,
                                                                       final ApplicationContext context) {

    final Map<String, CommandHandler> registry = new HashMap<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
    scanner.addIncludeFilter(new AssignableTypeFilter(CommandHandler.class));

    CommandHandler currentHandler = null;

    for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) {
        currentHandler = (CommandHandler) beanFactory.createBean(ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()),
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
        registry.put(currentHandler.getInterest().getName(), currentHandler);
    }

    return registry;
}
 
开发者ID:sem2nawara,项目名称:acme-solution,代码行数:19,代码来源:CommandHandlerUtils.java


注:本文中的org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。