org.springframework.context.annotation

## Class ConfigurationClassPostProcessor

- java.lang.Object
- - org.springframework.context.annotation.ConfigurationClassPostProcessor

- All Implemented Interfaces:
    Aware, BeanClassLoaderAware, BeanFactoryPostProcessor, BeanDefinitionRegistryPostProcessor, ApplicationStartupAware, EnvironmentAware, ResourceLoaderAware, Ordered, PriorityOrdered

      public class ConfigurationClassPostProcessor
      extends Object
      implements BeanDefinitionRegistryPostProcessor, PriorityOrdered, ResourceLoaderAware, ApplicationStartupAware, 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 priority-ordered as it is important that any `@Bean` methods declared in `@Configuration` classes have their corresponding bean definitions registered before any other `BeanFactoryPostProcessor` executes.

  Since:
    3.0
  Author:
    Chris Beams, Juergen Hoeller, Phillip Webb, Sam Brannen

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static AnnotationBeanNameGenerator` | `IMPORT_BEAN_NAME_GENERATOR` A `BeanNameGenerator` using fully qualified class names as default bean names.

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConfigurationClassPostProcessor()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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()` Get the order value of this object.
    `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` | `setApplicationStartup(ApplicationStartup applicationStartup)` Set the ApplicationStartup that this object runs with.
    `void` | `setBeanClassLoader(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 component 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

    - #### IMPORT_BEAN_NAME_GENERATOR

          public static final AnnotationBeanNameGenerator IMPORT_BEAN_NAME_GENERATOR

      A `BeanNameGenerator` using fully qualified class names as default bean names.

      This default for configuration-level import purposes may be overridden through `setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator)`. Note that the default for component scanning purposes is a plain `AnnotationBeanNameGenerator.INSTANCE`, unless overridden through `setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator)` with a unified user-level bean name generator.

      Since:
        5.2
      See Also:
        `setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator)`

  - ### Constructor Detail

    - #### ConfigurationClassPostProcessor

          public ConfigurationClassPostProcessor()

  - ### Method Detail

    - #### getOrder

          public int getOrder()

      Description copied from interface: `Ordered`
      Get the order value of this object.

      Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet `load-on-startup` values).

      Same order values will result in arbitrary sort positions for the affected objects.

      Specified by:
        `getOrder` in interface `Ordered`
      Returns:
        the order value
      See Also:
        `Ordered.HIGHEST_PRECEDENCE`, `Ordered.LOWEST_PRECEDENCE`

    - #### setSourceExtractor

          public void setSourceExtractor(@Nullable
                                         SourceExtractor sourceExtractor)

      Set the `SourceExtractor` to use for generated bean definitions that correspond to `Bean` factory methods.

    - #### setProblemReporter

          public void setProblemReporter(@Nullable
                                         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.

    - #### setBeanNameGenerator

          public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator)

      Set the `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 set here.

      Since:
        3.1.1
      See Also:
        `AnnotationConfigApplicationContext.setBeanNameGenerator(BeanNameGenerator)`, `AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR`

    - #### setEnvironment

          public void setEnvironment(Environment environment)

      Description copied from interface: `EnvironmentAware`
      Set the `Environment` that this component 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` - the ResourceLoader object to be used by this object
      See Also:
        `ResourcePatternResolver`, `ResourcePatternUtils.getResourcePatternResolver(org.springframework.core.io.ResourceLoader)`

    - #### setBeanClassLoader

          public void setBeanClassLoader(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

    - #### setApplicationStartup

          public void setApplicationStartup(ApplicationStartup applicationStartup)

      Description copied from interface: `ApplicationStartupAware`
      Set the ApplicationStartup that this object runs with.

      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:
        `setApplicationStartup` in interface `ApplicationStartupAware`
      Parameters:
        `applicationStartup` - application startup to be used by this object

    - #### 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

    - #### 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`