Skip to content

Commit 88d681f

Browse files
committed
Register bean for IntComponentScanRegistrar
To avoid duplication for scanning register a `IntegrationComponentScanRegistrar` as a bean by itself and check for its presence before scanning * Exclude this bean definition from the AOT since its logic has already passed on AOT generation and we don't need this bean at runtime any more
1 parent 18fcd21 commit 88d681f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aot/IntegrationBeanRegistrationExcludeFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter;
2222
import org.springframework.beans.factory.support.RegisteredBean;
2323
import org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor;
24+
import org.springframework.integration.config.IntegrationComponentScanRegistrar;
2425
import org.springframework.integration.config.IntegrationConfigurationBeanFactoryPostProcessor;
2526

2627
/**
@@ -39,7 +40,8 @@ class IntegrationBeanRegistrationExcludeFilter implements BeanRegistrationExclud
3940
public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
4041
Class<?> beanClass = registeredBean.getBeanClass();
4142
return Arrays.asList(DefaultConfiguringBeanFactoryPostProcessor.class,
42-
IntegrationConfigurationBeanFactoryPostProcessor.class)
43+
IntegrationConfigurationBeanFactoryPostProcessor.class,
44+
IntegrationComponentScanRegistrar.class)
4345
.contains(beanClass);
4446
}
4547

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationComponentScanRegistrar.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@
2525
import java.util.Set;
2626
import java.util.regex.Pattern;
2727

28+
import org.apache.commons.logging.Log;
29+
import org.apache.commons.logging.LogFactory;
30+
2831
import org.springframework.beans.BeanUtils;
2932
import org.springframework.beans.factory.Aware;
3033
import org.springframework.beans.factory.BeanClassLoaderAware;
3134
import org.springframework.beans.factory.BeanFactory;
3235
import org.springframework.beans.factory.BeanFactoryAware;
3336
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
37+
import org.springframework.beans.factory.config.BeanDefinition;
3438
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
39+
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
3540
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3641
import org.springframework.beans.factory.support.BeanNameGenerator;
3742
import org.springframework.context.EnvironmentAware;
@@ -66,6 +71,10 @@
6671
public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRegistrar,
6772
ResourceLoaderAware, EnvironmentAware {
6873

74+
private static final Log LOGGER = LogFactory.getLog(IntegrationComponentScanRegistrar.class);
75+
76+
private static final String BEAN_NAME = IntegrationComponentScanRegistrar.class.getName();
77+
6978
private final List<TypeFilter> defaultFilters = new ArrayList<>();
7079

7180
private ResourceLoader resourceLoader;
@@ -94,6 +103,16 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
94103

95104
Assert.notNull(componentScan, "The '@IntegrationComponentScan' must be present for using this registrar");
96105

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+
97116
Collection<String> basePackages = getBasePackages(componentScan, registry);
98117

99118
if (basePackages.isEmpty()) {

0 commit comments

Comments
 (0)