ConfigurationClassPostProcessor
基于 springboot3.2 和 springframework6.1.4
1. ConfigurationClassPostProcessor的注册过程
ConfigurationClassPostProcessor
是 Spring Framework 中的一个关键后置处理器,用于处理 @Configuration
注解的类,并生成相应的 Bean 定义。下面是 ConfigurationClassPostProcessor
的加载过程:
- 注册
ConfigurationClassPostProcessor
:- 通过调用
AnnotationConfigUtils.registerAnnotationConfigProcessors(registry)
方法,将ConfigurationClassPostProcessor
注册到BeanDefinitionRegistry
中。 - 这通常在应用程序上下文的初始化过程中自动完成,例如在
AnnotationConfigServletWebServerApplicationContext
的构造函数中。
- 通过调用
public AnnotationConfigServletWebServerApplicationContext() {
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment) {
Assert.notNull(registry,