|
25 | 25 | import java.util.Set; |
26 | 26 | import java.util.regex.Pattern; |
27 | 27 |
|
| 28 | +import org.apache.commons.logging.Log; |
| 29 | +import org.apache.commons.logging.LogFactory; |
| 30 | + |
28 | 31 | import org.springframework.beans.BeanUtils; |
29 | 32 | import org.springframework.beans.factory.Aware; |
30 | 33 | import org.springframework.beans.factory.BeanClassLoaderAware; |
31 | 34 | import org.springframework.beans.factory.BeanFactory; |
32 | 35 | import org.springframework.beans.factory.BeanFactoryAware; |
33 | 36 | import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; |
| 37 | +import org.springframework.beans.factory.config.BeanDefinition; |
34 | 38 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; |
| 39 | +import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
35 | 40 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
36 | 41 | import org.springframework.beans.factory.support.BeanNameGenerator; |
37 | 42 | import org.springframework.context.EnvironmentAware; |
|
66 | 71 | public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRegistrar, |
67 | 72 | ResourceLoaderAware, EnvironmentAware { |
68 | 73 |
|
| 74 | + private static final Log LOGGER = LogFactory.getLog(IntegrationComponentScanRegistrar.class); |
| 75 | + |
| 76 | + private static final String BEAN_NAME = IntegrationComponentScanRegistrar.class.getName(); |
| 77 | + |
69 | 78 | private final List<TypeFilter> defaultFilters = new ArrayList<>(); |
70 | 79 |
|
71 | 80 | private ResourceLoader resourceLoader; |
@@ -94,6 +103,16 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B |
94 | 103 |
|
95 | 104 | Assert.notNull(componentScan, "The '@IntegrationComponentScan' must be present for using this registrar"); |
96 | 105 |
|
| 106 | + if (registry.containsBeanDefinition(BEAN_NAME)) { |
| 107 | + LOGGER.warn("Only one '@IntegrationComponentScan' can be present.\nConsider to merge them all to one."); |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + registry.registerBeanDefinition(BEAN_NAME, |
| 112 | + BeanDefinitionBuilder.genericBeanDefinition(IntegrationComponentScanRegistrar.class, () -> this) |
| 113 | + .setRole(BeanDefinition.ROLE_INFRASTRUCTURE) |
| 114 | + .getBeanDefinition()); |
| 115 | + |
97 | 116 | Collection<String> basePackages = getBasePackages(componentScan, registry); |
98 | 117 |
|
99 | 118 | if (basePackages.isEmpty()) { |
|
0 commit comments