ConfigurationClassPostProcessor

What

ConfigurationClassPostProcessorBeanFactoryPostProcessor的一个实现类,并且实现了PriorityOrdered接口,如下图所示:

classDiagram
    BeanFactoryPostProcessor <|-- BeanDefinitionRegistryPostProcessor
    BeanDefinitionRegistryPostProcessor <|-- ConfigurationClassPostProcessor
    PriorityOrdered <|-- ConfigurationClassPostProcessor

How

ConfigurableApplicationContextrefresh()过程中,postProcessBeanDefinitionRegistry()postProcessBeanFactory()方法被依次回调,触发processConfigBeanDefinitions()的执行,流程如下图所示:

flowchart TD
	a1["postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)"]
    a2["postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)"]
    subgraph one["processConfigBeanDefinitions(registry)"]
    b1["String[] candidateNames = registry.getBeanDefinitionNames();"]
    b2["ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.metadataReaderFactory)"]
	b3["configCandidates.sort((bd1, bd2))"]    
    b1-->b2-->b3
    end
    a1 --> one
    a2 --> one

processConfigBeanDefinitions()方法中,主要有两个功能:

  1. BeanDefinitionRegistry找到符合ConfigurationClass定义的BeanDefinition并排序;
  2. 使用ConfigurationClassParser解析ConfigurationClass