當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。