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
This commit is contained in:
@@ -21,6 +21,7 @@ import java.util.Arrays;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor;
|
||||
import org.springframework.integration.config.IntegrationComponentScanRegistrar;
|
||||
import org.springframework.integration.config.IntegrationConfigurationBeanFactoryPostProcessor;
|
||||
|
||||
/**
|
||||
@@ -39,7 +40,8 @@ class IntegrationBeanRegistrationExcludeFilter implements BeanRegistrationExclud
|
||||
public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
|
||||
Class<?> beanClass = registeredBean.getBeanClass();
|
||||
return Arrays.asList(DefaultConfiguringBeanFactoryPostProcessor.class,
|
||||
IntegrationConfigurationBeanFactoryPostProcessor.class)
|
||||
IntegrationConfigurationBeanFactoryPostProcessor.class,
|
||||
IntegrationComponentScanRegistrar.class)
|
||||
.contains(beanClass);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,18 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.Aware;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
@@ -66,6 +71,10 @@ import org.springframework.util.StringUtils;
|
||||
public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRegistrar,
|
||||
ResourceLoaderAware, EnvironmentAware {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(IntegrationComponentScanRegistrar.class);
|
||||
|
||||
private static final String BEAN_NAME = IntegrationComponentScanRegistrar.class.getName();
|
||||
|
||||
private final List<TypeFilter> defaultFilters = new ArrayList<>();
|
||||
|
||||
private ResourceLoader resourceLoader;
|
||||
@@ -94,6 +103,16 @@ public class IntegrationComponentScanRegistrar implements ImportBeanDefinitionRe
|
||||
|
||||
Assert.notNull(componentScan, "The '@IntegrationComponentScan' must be present for using this registrar");
|
||||
|
||||
if (registry.containsBeanDefinition(BEAN_NAME)) {
|
||||
LOGGER.warn("Only one '@IntegrationComponentScan' can be present.\nConsider to merge them all to one.");
|
||||
return;
|
||||
}
|
||||
|
||||
registry.registerBeanDefinition(BEAN_NAME,
|
||||
BeanDefinitionBuilder.genericBeanDefinition(IntegrationComponentScanRegistrar.class, () -> this)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
.getBeanDefinition());
|
||||
|
||||
Collection<String> basePackages = getBasePackages(componentScan, registry);
|
||||
|
||||
if (basePackages.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user