BeanFactoryPostProcessor&BeanDefinitionRegistryPostProcessor
BeanFactoryPostProcessor&BeanDefinitionRegistryPostProcessor
BeanPostProcessor:bean后置处理器,创建对象初始化的时候进行拦截
BeanFactoryPostProcessor
1、BeanFactoryPostProcessor(All bean definitions will have been loaded, but no beans will have been instantiated yet.):beanFactory的后置处理器()
在BeanFactory标准初始化之后调用,所有的bean定义已经保存加载到beanFactory,但是bean实例已经创建
1)、IOC容器创建对象
2)、invokeBeanFactoryPostProcessors(beanFactory);指行BeanFactoryPostProcessor
如何找到BeanFactoryPostProcessors来执行他们的方法
①直接在BeanFactory中找到所有的BeanFactoryPostProcessors的组件,并执行他们的方法
②在初始化创建其他组件签名执行
BeanDefinitionRegistryPostProcessor
BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor
postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
所有bean定义信息将要被加载,bean实例还未创建
优先于BeanFactoryPostProcessors执行
利用BeanDefinitionRegistryPostProcessor给容器再添加一些组件
原理
1)、ioc容器创建
2)、refresh()=>invokeBeanFactoryPostProcessors(beanFactory);
3)、先从容器中获取到所有的BeanDefinitionRegistryPostProcessor组件。
①依次触发所有的postProcessBeanDefinitionRegistry()方法
②再来触发postProcessBeanFactory()方法
4)、再来从容器中找到BeanFactoryPostProcessors组件,然后来执行他们的方法

浙公网安备 33010602011771号