|
|
|
@ -27,7 +27,7 @@ import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.springframework.beans.BeansException; |
|
|
|
|
|
|
|
import org.springframework.beans.PropertyValues; |
|
|
|
import org.springframework.beans.PropertyValues; |
|
|
|
import org.springframework.beans.factory.BeanClassLoaderAware; |
|
|
|
import org.springframework.beans.factory.BeanClassLoaderAware; |
|
|
|
import org.springframework.beans.factory.BeanDefinitionStoreException; |
|
|
|
import org.springframework.beans.factory.BeanDefinitionStoreException; |
|
|
|
@ -90,7 +90,7 @@ import static org.springframework.context.annotation.AnnotationConfigUtils.*; |
|
|
|
* @since 3.0 |
|
|
|
* @since 3.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor, |
|
|
|
public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor, |
|
|
|
ResourceLoaderAware, BeanClassLoaderAware, EnvironmentAware, PriorityOrdered { |
|
|
|
PriorityOrdered, ResourceLoaderAware, BeanClassLoaderAware, EnvironmentAware { |
|
|
|
|
|
|
|
|
|
|
|
private static final String IMPORT_AWARE_PROCESSOR_BEAN_NAME = |
|
|
|
private static final String IMPORT_AWARE_PROCESSOR_BEAN_NAME = |
|
|
|
ConfigurationClassPostProcessor.class.getName() + ".importAwareProcessor"; |
|
|
|
ConfigurationClassPostProcessor.class.getName() + ".importAwareProcessor"; |
|
|
|
@ -138,6 +138,10 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public int getOrder() { |
|
|
|
|
|
|
|
return Ordered.LOWEST_PRECEDENCE; // within PriorityOrdered
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the {@link SourceExtractor} to use for generated bean definitions |
|
|
|
* Set the {@link SourceExtractor} to use for generated bean definitions |
|
|
|
@ -318,7 +322,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo |
|
|
|
this.importBeanNameGenerator); |
|
|
|
this.importBeanNameGenerator); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
reader.loadBeanDefinitions(parser.getConfigurationClasses()); |
|
|
|
this.reader.loadBeanDefinitions(parser.getConfigurationClasses()); |
|
|
|
|
|
|
|
|
|
|
|
// Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
|
|
|
|
// Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
|
|
|
|
if (singletonRegistry != null) { |
|
|
|
if (singletonRegistry != null) { |
|
|
|
@ -374,23 +378,23 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public int getOrder() { |
|
|
|
|
|
|
|
return Ordered.LOWEST_PRECEDENCE; // within PriorityOrdered
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class ImportAwareBeanPostProcessor implements PriorityOrdered, BeanFactoryAware, BeanPostProcessor { |
|
|
|
private static class ImportAwareBeanPostProcessor implements BeanPostProcessor, PriorityOrdered, BeanFactoryAware { |
|
|
|
|
|
|
|
|
|
|
|
private BeanFactory beanFactory; |
|
|
|
private BeanFactory beanFactory; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { |
|
|
|
public int getOrder() { |
|
|
|
|
|
|
|
return Ordered.HIGHEST_PRECEDENCE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setBeanFactory(BeanFactory beanFactory) { |
|
|
|
this.beanFactory = beanFactory; |
|
|
|
this.beanFactory = beanFactory; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { |
|
|
|
public Object postProcessBeforeInitialization(Object bean, String beanName) { |
|
|
|
if (bean instanceof ImportAware) { |
|
|
|
if (bean instanceof ImportAware) { |
|
|
|
ImportRegistry importRegistry = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class); |
|
|
|
ImportRegistry importRegistry = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class); |
|
|
|
String importingClass = importRegistry.getImportingClassFor(bean.getClass().getSuperclass().getName()); |
|
|
|
String importingClass = importRegistry.getImportingClassFor(bean.getClass().getSuperclass().getName()); |
|
|
|
@ -413,14 +417,9 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName) { |
|
|
|
return bean; |
|
|
|
return bean; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public int getOrder() { |
|
|
|
|
|
|
|
return Ordered.HIGHEST_PRECEDENCE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -429,9 +428,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo |
|
|
|
* {@link EnhancedConfiguration} beans are injected with the {@link BeanFactory} |
|
|
|
* {@link EnhancedConfiguration} beans are injected with the {@link BeanFactory} |
|
|
|
* before the {@link AutowiredAnnotationBeanPostProcessor} runs (SPR-10668). |
|
|
|
* before the {@link AutowiredAnnotationBeanPostProcessor} runs (SPR-10668). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static class EnhancedConfigurationBeanPostProcessor extends |
|
|
|
private static class EnhancedConfigurationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter |
|
|
|
InstantiationAwareBeanPostProcessorAdapter implements PriorityOrdered, |
|
|
|
implements PriorityOrdered, BeanFactoryAware { |
|
|
|
BeanFactoryAware { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BeanFactory beanFactory; |
|
|
|
private BeanFactory beanFactory; |
|
|
|
|
|
|
|
|
|
|
|
@ -441,22 +439,19 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public PropertyValues postProcessPropertyValues(PropertyValues pvs, |
|
|
|
public void setBeanFactory(BeanFactory beanFactory) { |
|
|
|
PropertyDescriptor[] pds, Object bean, String beanName) |
|
|
|
this.beanFactory = beanFactory; |
|
|
|
throws BeansException { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) { |
|
|
|
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
|
|
|
|
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
|
|
|
|
// postProcessPropertyValues method attempts to auto-wire other configuration
|
|
|
|
// postProcessPropertyValues method attempts to auto-wire other configuration beans.
|
|
|
|
// beans.
|
|
|
|
|
|
|
|
if (bean instanceof EnhancedConfiguration) { |
|
|
|
if (bean instanceof EnhancedConfiguration) { |
|
|
|
((EnhancedConfiguration) bean).setBeanFactory(this.beanFactory); |
|
|
|
((EnhancedConfiguration) bean).setBeanFactory(this.beanFactory); |
|
|
|
} |
|
|
|
} |
|
|
|
return pvs; |
|
|
|
return pvs; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { |
|
|
|
|
|
|
|
this.beanFactory = beanFactory; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|