org.springframework.context.annotation
Class ConfigurationClassPostProcessor

java.lang.Object
  extended by org.springframework.context.annotation.ConfigurationClassPostProcessor
All Implemented Interfaces:
Aware, BeanClassLoaderAware, BeanFactoryPostProcessor, BeanDefinitionRegistryPostProcessor, EnvironmentAware, ResourceLoaderAware

public class ConfigurationClassPostProcessor
extends java.lang.Object
implements BeanDefinitionRegistryPostProcessor, 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.

Since:
3.0
Author:
Chris Beams, Juergen Hoeller

Nested Class Summary
private static class ConfigurationClassPostProcessor.ImportAwareBeanPostProcessor
           
 
Field Summary
private  java.lang.ClassLoader beanClassLoader
           
private static boolean cglibAvailable
          Whether the CGLIB2 library is present on the classpath
private  Environment environment
           
private  java.util.Set<java.lang.Integer> factoriesPostProcessed
           
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
           
 
Constructor Summary
ConfigurationClassPostProcessor()
           
 
Method Summary
 void enhanceConfigurationClasses(ConfigurableListableBeanFactory beanFactory)
          Post-processes a BeanFactory in search of Configuration class BeanDefinitions; any candidates are then enhanced by a ConfigurationClassEnhancer.
private  ConfigurationClassBeanDefinitionReader getConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry)
           
 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cglibAvailable

private static final boolean cglibAvailable
Whether the CGLIB2 library is present on the classpath


logger

private final Log logger

sourceExtractor

private SourceExtractor sourceExtractor

problemReporter

private ProblemReporter problemReporter

environment

private Environment environment

resourceLoader

private ResourceLoader resourceLoader

beanClassLoader

private java.lang.ClassLoader beanClassLoader

metadataReaderFactory

private MetadataReaderFactory metadataReaderFactory

setMetadataReaderFactoryCalled

private boolean setMetadataReaderFactoryCalled

registriesPostProcessed

private final java.util.Set<java.lang.Integer> registriesPostProcessed

factoriesPostProcessed

private final java.util.Set<java.lang.Integer> factoriesPostProcessed

reader

private ConfigurationClassBeanDefinitionReader reader
Constructor Detail

ConfigurationClassPostProcessor

public ConfigurationClassPostProcessor()
Method Detail

setSourceExtractor

public void setSourceExtractor(SourceExtractor sourceExtractor)
Set the SourceExtractor to use for generated bean definitions that correspond to Bean factory methods.


setProblemReporter

public void setProblemReporter(ProblemReporter problemReporter)
Set the 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.


setMetadataReaderFactory

public void setMetadataReaderFactory(MetadataReaderFactory metadataReaderFactory)
Set the MetadataReaderFactory to use.

Default is a CachingMetadataReaderFactory for the specified bean class loader.


setEnvironment

public void setEnvironment(Environment environment)
Description copied from interface: EnvironmentAware
Set the Environment that this object runs in.

Specified by:
setEnvironment in interface EnvironmentAware

setResourceLoader

public void setResourceLoader(ResourceLoader resourceLoader)
Description copied from interface: ResourceLoaderAware
Set the ResourceLoader that this object runs in.

This 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.

Specified by:
setResourceLoader in interface ResourceLoaderAware
Parameters:
resourceLoader - ResourceLoader object to be used by this object
See Also:
ResourcePatternResolver, ResourcePatternUtils.getResourcePatternResolver(org.springframework.core.io.ResourceLoader)

setBeanClassLoader

public void setBeanClassLoader(java.lang.ClassLoader beanClassLoader)
Description copied from interface: BeanClassLoaderAware
Callback that supplies the bean class 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.

Specified by:
setBeanClassLoader in interface BeanClassLoaderAware
Parameters:
beanClassLoader - the owning class loader; may be null in which case a default ClassLoader must be used, for example the ClassLoader obtained via ClassUtils.getDefaultClassLoader()

postProcessBeanDefinitionRegistry

public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
Derive further bean definitions from the configuration classes in the registry.

Specified by:
postProcessBeanDefinitionRegistry in interface BeanDefinitionRegistryPostProcessor
Parameters:
registry - the bean definition registry used by the application context

postProcessBeanFactory

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
Prepare the Configuration classes for servicing bean requests at runtime by replacing them with CGLIB-enhanced subclasses.

Specified by:
postProcessBeanFactory in interface BeanFactoryPostProcessor
Parameters:
beanFactory - the bean factory used by the application context

getConfigurationClassBeanDefinitionReader

private ConfigurationClassBeanDefinitionReader getConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry)

processConfigBeanDefinitions

public void processConfigBeanDefinitions(BeanDefinitionRegistry registry)
Build and validate a configuration model based on the registry of Configuration classes.


enhanceConfigurationClasses

public void enhanceConfigurationClasses(ConfigurableListableBeanFactory beanFactory)
Post-processes a BeanFactory in search of Configuration class BeanDefinitions; any candidates are then enhanced by a ConfigurationClassEnhancer. Candidate status is determined by BeanDefinition attribute metadata.

See Also:
ConfigurationClassEnhancer