类结构图:
通过类结构图清楚的了解到BeanDefinitionRegistryPostProcessor继承了BeanFactoryPostProcessor接口,关于BeanFactoryPostProcessor接口不了的朋友可以查看Spring Boot 源码分析 —— 后置处理器
源码注释:
/**
* Extension to the standard {@link BeanFactoryPostProcessor} SPI, allowing for
* the registration of further bean definitions <i>before</i> regular
* BeanFactoryPostProcessor detection kicks in. In particular,
* BeanDefinitionRegistryPostProcessor may register further bean definitions
* which in turn define BeanFactoryPostProcessor instances.
*
* @author Juergen Hoeller
* @since 3.0.1
* @see org.springframework.context.annotation.ConfigurationClassPostProcessor
*/
public interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor {
/**
* Modify the application context's internal bean definition registry after its
* standard initialization. All regular bean definitions will have been loaded,
* but no beans will have been instantiated yet. This allows for adding further
* bean definitions before the next post-processing phase kicks in.
* @param registry the bean definition registry used by the application context
* @throws org.springframework.beans.BeansException in case of errors
*/
void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException;
}
接口注释:
对标准{@link BeanFactoryPostProcessor}SPI的扩展,允许在常规BeanFactoryPostProcessor检测启动之前进一步的注册bean定义。特别是,BeanDefinitionRegistryPostProcessor可以注册其他bean定义
方法注释:
在标准初始化后修改应用程序上下文的内部bean定义注册表。所有常规bean定义都将被加载,但bean没有被实例化。这允许在下一个后处理阶段开始添加更多的bean定义。
总结:
BeanDefinitionRegistryPostProcessor与BeanFactoryPostProcessor可以在容器所有bean实例化之前对所有BeanDefinition进行定义、修改、删除。
个人建议:
BeanDefinitionRegistryPostProcessor做bean的定义
BeanFactoryPostProcessor用作BeanDefinition修改
以上属于原创文章,转载请注明作者@怪咖
QQ:208275451