public class ConfigurationClassPostProcessor extends java.lang.Object implements BeanDefinitionRegistryPostProcessor, PriorityOrdered, ResourceLoaderAware, BeanClassLoaderAware, EnvironmentAware
BeanFactoryPostProcessor used for bootstrapping processing of
@Configuration classes.
Registered by default when using <context:annotation-config/> or
<context:component-scan/>. Otherwise, may be declared manually as
with any other BeanFactoryPostProcessor.
This post processor is Ordered.HIGHEST_PRECEDENCE as it is important
that any Bean methods declared in Configuration classes have their
respective bean definitions registered before any other BeanFactoryPostProcessor
executes.
| Modifier and Type | Class and Description |
|---|---|
private static class |
ConfigurationClassPostProcessor.EnhancedConfigurationBeanPostProcessor
InstantiationAwareBeanPostProcessorAdapter that ensures
ConfigurationClassEnhancer.EnhancedConfiguration beans are injected with the BeanFactory
before the AutowiredAnnotationBeanPostProcessor runs (SPR-10668). |
private static class |
ConfigurationClassPostProcessor.ImportAwareBeanPostProcessor |
| Modifier and Type | Field and Description |
|---|---|
private java.lang.ClassLoader |
beanClassLoader |
private BeanNameGenerator |
componentScanBeanNameGenerator |
private static java.lang.String |
ENHANCED_CONFIGURATION_PROCESSOR_BEAN_NAME |
private Environment |
environment |
private java.util.Set<java.lang.Integer> |
factoriesPostProcessed |
private static java.lang.String |
IMPORT_AWARE_PROCESSOR_BEAN_NAME |
private static java.lang.String |
IMPORT_REGISTRY_BEAN_NAME |
private BeanNameGenerator |
importBeanNameGenerator |
private boolean |
localBeanNameGeneratorSet |
private Log |
logger |
private MetadataReaderFactory |
metadataReaderFactory |
private ProblemReporter |
problemReporter |
private ConfigurationClassBeanDefinitionReader |
reader |
private java.util.Set<java.lang.Integer> |
registriesPostProcessed |
private ResourceLoader |
resourceLoader |
private boolean |
setMetadataReaderFactoryCalled |
private SourceExtractor |
sourceExtractor |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| Constructor and Description |
|---|
ConfigurationClassPostProcessor() |
| Modifier and Type | Method and Description |
|---|---|
void |
enhanceConfigurationClasses(ConfigurableListableBeanFactory beanFactory)
Post-processes a BeanFactory in search of Configuration class BeanDefinitions;
any candidates are then enhanced by a
ConfigurationClassEnhancer. |
int |
getOrder()
Return the order value of this object, with a
higher value meaning greater in terms of sorting.
|
void |
postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
Derive further bean definitions from the configuration classes in the registry.
|
void |
postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
Prepare the Configuration classes for servicing bean requests at runtime
by replacing them with CGLIB-enhanced subclasses.
|
void |
processConfigBeanDefinitions(BeanDefinitionRegistry registry)
Build and validate a configuration model based on the registry of
Configuration classes. |
void |
setBeanClassLoader(java.lang.ClassLoader beanClassLoader)
Callback that supplies the bean
class loader to
a bean instance. |
void |
setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
Set the
BeanNameGenerator to be used when triggering component scanning
from Configuration classes and when registering Import'ed
configuration classes. |
void |
setEnvironment(Environment environment)
Set the
Environment that this object runs in. |
void |
setMetadataReaderFactory(MetadataReaderFactory metadataReaderFactory)
Set the
MetadataReaderFactory to use. |
void |
setProblemReporter(ProblemReporter problemReporter)
Set the
ProblemReporter to use. |
void |
setResourceLoader(ResourceLoader resourceLoader)
Set the ResourceLoader that this object runs in.
|
void |
setSourceExtractor(SourceExtractor sourceExtractor)
Set the
SourceExtractor to use for generated bean definitions
that correspond to Bean factory methods. |
private static final java.lang.String IMPORT_AWARE_PROCESSOR_BEAN_NAME
private static final java.lang.String IMPORT_REGISTRY_BEAN_NAME
private static final java.lang.String ENHANCED_CONFIGURATION_PROCESSOR_BEAN_NAME
private final Log logger
private SourceExtractor sourceExtractor
private ProblemReporter problemReporter
private Environment environment
private ResourceLoader resourceLoader
private java.lang.ClassLoader beanClassLoader
private MetadataReaderFactory metadataReaderFactory
private boolean setMetadataReaderFactoryCalled
private final java.util.Set<java.lang.Integer> registriesPostProcessed
private final java.util.Set<java.lang.Integer> factoriesPostProcessed
private ConfigurationClassBeanDefinitionReader reader
private boolean localBeanNameGeneratorSet
private BeanNameGenerator componentScanBeanNameGenerator
private BeanNameGenerator importBeanNameGenerator
public int getOrder()
OrderedNormally starting with 0, with Integer.MAX_VALUE
indicating the greatest value. Same order values will result
in arbitrary positions for the affected objects.
Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).
public void setSourceExtractor(SourceExtractor sourceExtractor)
SourceExtractor to use for generated bean definitions
that correspond to Bean factory methods.public void setProblemReporter(ProblemReporter problemReporter)
ProblemReporter to use.
Used to register any problems detected with Configuration or Bean
declarations. For instance, an @Bean method marked as final is illegal
and would be reported as a problem. Defaults to FailFastProblemReporter.
public void setMetadataReaderFactory(MetadataReaderFactory metadataReaderFactory)
MetadataReaderFactory to use.
Default is a CachingMetadataReaderFactory for the specified
bean class loader.
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
BeanNameGenerator to be used when triggering component scanning
from Configuration classes and when registering Import'ed
configuration classes. The default is a standard AnnotationBeanNameGenerator
for scanned components (compatible with the default in ClassPathBeanDefinitionScanner)
and a variant thereof for imported configuration classes (using unique fully-qualified
class names instead of standard component overriding).
Note that this strategy does not apply to Bean methods.
This setter is typically only appropriate when configuring the post-processor as
a standalone bean definition in XML, e.g. not using the dedicated
AnnotationConfig* application contexts or the <context:annotation-config> element. Any bean name generator specified against
the application context will take precedence over any value set here.
public void setEnvironment(Environment environment)
EnvironmentAwareEnvironment that this object runs in.setEnvironment in interface EnvironmentAwarepublic void setResourceLoader(ResourceLoader resourceLoader)
ResourceLoaderAwareThis might be a ResourcePatternResolver, which can be checked
through instanceof ResourcePatternResolver. See also the
ResourcePatternUtils.getResourcePatternResolver method.
Invoked after population of normal bean properties but before an init callback
like InitializingBean's afterPropertiesSet or a custom init-method.
Invoked before ApplicationContextAware's setApplicationContext.
setResourceLoader in interface ResourceLoaderAwareresourceLoader - ResourceLoader object to be used by this objectResourcePatternResolver,
ResourcePatternUtils.getResourcePatternResolver(org.springframework.core.io.ResourceLoader)public void setBeanClassLoader(java.lang.ClassLoader beanClassLoader)
BeanClassLoaderAwareclass loader to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.
setBeanClassLoader in interface BeanClassLoaderAwarebeanClassLoader - the owning class loader; may be null in
which case a default ClassLoader must be used, for example
the ClassLoader obtained via
ClassUtils.getDefaultClassLoader()public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
postProcessBeanDefinitionRegistry in interface BeanDefinitionRegistryPostProcessorregistry - the bean definition registry used by the application contextpublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
postProcessBeanFactory in interface BeanFactoryPostProcessorbeanFactory - the bean factory used by the application contextpublic void processConfigBeanDefinitions(BeanDefinitionRegistry registry)
Configuration classes.public void enhanceConfigurationClasses(ConfigurableListableBeanFactory beanFactory)
ConfigurationClassEnhancer.
Candidate status is determined by BeanDefinition attribute metadata.ConfigurationClassEnhancer