List of usage examples for org.springframework.context.annotation ClassPathScanningCandidateComponentProvider findCandidateComponents
public Set<BeanDefinition> findCandidateComponents(String basePackage)
From source file:io.gravitee.repository.mongodb.common.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);//from w w w .ja v a 2s .co m 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; }
From source file:org.datamongo.jira.datamongo1064.mapper.EmbeddedObjectTypeInformationMapper.java
/** * Scans the mapping base package for classes annotated with {@link Embeddable}. * //ww w .j a v a 2 s. c om * @see #getMappingBasePackage() * @return * @throws ClassNotFoundException */ protected Map<Class<?>, String> getInitialEntitySet() throws ClassNotFoundException { String[] basePackage = this.basePackage; Map<Class<?>, String> initialEntitySet = new HashMap<Class<?>, String>(); if (basePackage != null) { for (String packageBase : basePackage) { if (StringUtils.hasText(packageBase)) { ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Embeddable.class)); for (BeanDefinition candidate : componentProvider.findCandidateComponents(packageBase)) { Class<?> forName = ClassUtils.forName(candidate.getBeanClassName(), AbstractMongoConfiguration.class.getClassLoader()); String alias = forName.getAnnotation(TypeAlias.class) != null ? forName.getAnnotation(TypeAlias.class).value() : forName.getName(); initialEntitySet.put(forName, alias); } } } } return initialEntitySet; }
From source file:com.springinpractice.ch11.oxm.ClasspathScanningJaxb2Marshaller.java
/** * @return//ww w . j a va 2 s . c o m * @throws Exception */ private Class<?>[] getXmlRootElementClasses() throws Exception { ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AnnotationTypeFilter(XmlRootElement.class)); List<Class<?>> classes = new ArrayList<Class<?>>(); for (String basePackage : basePackages) { Set<BeanDefinition> definitions = scanner.findCandidateComponents(basePackage); for (BeanDefinition definition : definitions) { String className = definition.getBeanClassName(); log.info("Found class: {}", className); classes.add(Class.forName(className)); } } return classes.toArray(new Class<?>[0]); }
From source file:com.couchbase.spring.config.AbstractCouchbaseConfiguration.java
/** * Scans the mapping base package for classes annotated with {@link Document}. *///w w w . ja va 2 s . c om 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(), AbstractCouchbaseConfiguration.class.getClassLoader())); } } return initialEntitySet; }
From source file:com.googlecode.icegem.cacheutils.common.PeerCacheService.java
/** * @param classLoader//from w w w . j av a 2 s.c om * @throws Exception */ private void registerClasses(ClassLoader classLoader) throws Exception { List<Class<?>> classesFromPackages = new ArrayList<Class<?>>(); for (String pack : scanPackages) { log.info("Scan package " + pack + " for classes marked by @AutoSerializable"); ClassPathScanningCandidateComponentProvider ppp = new ClassPathScanningCandidateComponentProvider( false); ppp.addIncludeFilter(new AnnotationTypeFilter(AutoSerializable.class)); Set<BeanDefinition> candidateComponents = ppp.findCandidateComponents(pack); for (BeanDefinition beanDefinition : candidateComponents) { String className = beanDefinition.getBeanClassName(); final Class<?> clazz = Class.forName(className); classesFromPackages.add(clazz); } } try { HierarchyRegistry.registerAll(classLoader, classesFromPackages); } catch (InvalidClassException e) { final String msg = "Some class from list " + classesFromPackages + " is nor serializable. Cause: " + e.getMessage(); log.error(msg); throw new RuntimeException(msg, e); } catch (CannotCompileException e) { final String msg = "Can't compile DataSerializer classes for some classes from list " + classesFromPackages + ". Cause: " + e.getMessage(); log.error(msg); throw new RuntimeException(msg, e); } }
From source file:com.thoughtworks.go.server.service.MagicalMaterialAndMaterialConfigConversionTest.java
@Test public void failIfNewTypeOfMaterialIsNotAddedInTheAboveTest() throws Exception { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false);// w ww .ja v a 2 s. co m provider.addIncludeFilter(new AssignableTypeFilter(MaterialConfig.class)); Set<BeanDefinition> candidateComponents = provider.findCandidateComponents("com/thoughtworks"); List<Class> reflectionsSubTypesOf = candidateComponents.stream() .map(beanDefinition -> beanDefinition.getBeanClassName()).map(s -> { try { return Class.forName(s); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }).collect(Collectors.toList()); reflectionsSubTypesOf.removeIf(this::isNotAConcrete_NonTest_MaterialConfigImplementation); List<Class> allExpectedMaterialConfigImplementations = allMaterialConfigsWhichAreDataPointsInThisTest(); assertThatAllMaterialConfigsInCodeAreTestedHere(reflectionsSubTypesOf, allExpectedMaterialConfigImplementations); }
From source file:com.walmart.gatling.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 *///from w ww.ja v a 2s . c o m 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); } } }
From source file:org.zalando.stups.spring.cloud.netflix.feign.OAuth2FeignClientsRegsitrar.java
@Override public void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata, final BeanDefinitionRegistry registry) { Set<String> basePackages = getBasePackages(importingClassMetadata); ClassPathScanningCandidateComponentProvider scanner = getScanner(); scanner.addIncludeFilter(new AnnotationTypeFilter(FeignClient.class)); scanner.setResourceLoader(this.resourceLoader); for (String basePackage : basePackages) { Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage); for (BeanDefinition candidateComponent : candidateComponents) { if (candidateComponent instanceof AnnotatedBeanDefinition) { // verify annotated class is an interface 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); }//from w w w. j a v a2s. c om } } }
From source file:org.agilemicroservices.autoconfigure.orm.RepositoryConfigurationDelegate.java
/** * Scans {@code repository.support} packages for implementations of {@link RepositoryFactorySupport}. Finding more * than a single type is considered a multi-store configuration scenario which will trigger stricter repository * scanning./*from w w w. j av a 2s .c o m*/ * * @return */ private boolean multipleStoresDetected() { ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.setEnvironment(environment); scanner.setResourceLoader(resourceLoader); scanner.addIncludeFilter(new LenientAssignableTypeFilter(RepositoryFactorySupport.class)); if (scanner.findCandidateComponents(MODULE_DETECTION_PACKAGE).size() > 1) { LOGGER.debug(MULTIPLE_MODULES); return true; } return false; }
From source file:com.googlecode.objectify.spring.ObjectifyFactoryBean.java
protected List<Class<?>> doScan() { List<Class<?>> classes = new ArrayList<Class<?>>(); String[] basePackages = StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); for (String basePackage : basePackages) { if (this.logger.isInfoEnabled()) { this.logger.info("Scanning package [" + basePackage + "]"); }// w w w . ja v a 2s .co m ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AnnotationTypeFilter(com.googlecode.objectify.annotation.Entity.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(javax.persistence.Entity.class)); Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage); for (BeanDefinition candidate : candidates) { Class<?> clazz = ClassUtils.resolveClassName(candidate.getBeanClassName(), ClassUtils.getDefaultClassLoader()); classes.add(clazz); } } return classes; }