Search in sources :

Example 1 with ImportBeanDefinitionRegistrar

use of org.springframework.context.annotation.ImportBeanDefinitionRegistrar in project spring-integration by spring-projects.

the class IntegrationComponentScanRegistrar method registerBeanDefinitions.

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    Map<String, Object> componentScan = importingClassMetadata.getAnnotationAttributes(IntegrationComponentScan.class.getName());
    Collection<String> basePackages = getBasePackages(importingClassMetadata, registry);
    if (basePackages.isEmpty()) {
        basePackages = Collections.singleton(ClassUtils.getPackageName(importingClassMetadata.getClassName()));
    }
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false) {

        @Override
        protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
            return beanDefinition.getMetadata().isIndependent() && !beanDefinition.getMetadata().isAnnotation();
        }
    };
    if ((boolean) componentScan.get("useDefaultFilters")) {
        for (TypeFilter typeFilter : this.componentRegistrars.keySet()) {
            scanner.addIncludeFilter(typeFilter);
        }
    }
    for (AnnotationAttributes filter : (AnnotationAttributes[]) componentScan.get("includeFilters")) {
        for (TypeFilter typeFilter : typeFiltersFor(filter, registry)) {
            scanner.addIncludeFilter(typeFilter);
        }
    }
    for (AnnotationAttributes filter : (AnnotationAttributes[]) componentScan.get("excludeFilters")) {
        for (TypeFilter typeFilter : typeFiltersFor(filter, registry)) {
            scanner.addExcludeFilter(typeFilter);
        }
    }
    scanner.setResourceLoader(this.resourceLoader);
    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);
        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {
                for (ImportBeanDefinitionRegistrar registrar : this.componentRegistrars.values()) {
                    registrar.registerBeanDefinitions(((AnnotatedBeanDefinition) candidateComponent).getMetadata(), registry);
                }
            }
        }
    }
}
Also used : IntegrationComponentScan(org.springframework.integration.annotation.IntegrationComponentScan) AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) TypeFilter(org.springframework.core.type.filter.TypeFilter) AspectJTypeFilter(org.springframework.core.type.filter.AspectJTypeFilter) AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) RegexPatternTypeFilter(org.springframework.core.type.filter.RegexPatternTypeFilter) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter) ImportBeanDefinitionRegistrar(org.springframework.context.annotation.ImportBeanDefinitionRegistrar) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)1 ImportBeanDefinitionRegistrar (org.springframework.context.annotation.ImportBeanDefinitionRegistrar)1 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)1 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)1 AspectJTypeFilter (org.springframework.core.type.filter.AspectJTypeFilter)1 AssignableTypeFilter (org.springframework.core.type.filter.AssignableTypeFilter)1 RegexPatternTypeFilter (org.springframework.core.type.filter.RegexPatternTypeFilter)1 TypeFilter (org.springframework.core.type.filter.TypeFilter)1 IntegrationComponentScan (org.springframework.integration.annotation.IntegrationComponentScan)1