BeanFactoryPostProcessor和BeanPostProcessor

1. BeanFactoryPostProcessor調用(見AbstractApplicationContext.refresh):

>> 建立DefaultListableBeanFactory --> loadBeanDefinitions
app

1)BeanDefinitionRegistryPostProcessor.postProcessBeanDefinitionRegistry(編碼註冊)post

2)BeanDefinitionRegistryPostProcessor.postProcessBeanDefinitionRegistry(配置註冊):PriorityOrdered排序 --> Ordered排序 --> 無序編碼

3)BeanFactoryPostProcessor.postProcessBeanFactory(編碼註冊):BeanDefinitionRegistryPostProcessor --> BeanFactoryPostProcessorspa

4)BeanFactoryPostProcessor.postProcessBeanFactory(配置註冊):PriorityOrdered排序 --> Ordered排序 --> 無序排序

 

2. BeanPostProcessor註冊:

1)PriorityOrdered排序 --> Ordered排序 --> 無序it

2)MergedBeanDefinitionPostProcessorio

 

3. BeanPostProcessor調用(見DefaultListableBeanFactory.createBean):

1)InstantiationAwareBeanPostProcessor.applyBeanPostProcessorsBeforeInstantiation(resolveBeforeInstantiation)table

>> 獲取bean --> 6class

>> createBeanInstance(默認:CglibSubclassingInstantiationStrategy.instantiate) --> 2容器

2)MergedBeanDefinitionPostProcessor.postProcessMergedBeanDefinitioInstantiationAwareBeanPostProcessor

3)InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation

>> autowireByName / autowireByType

4)InstantiationAwareBeanPostProcessor.postProcessPropertyValues

>> applyPropertyValues

5)BeanPostProcessor.postProcessBeforeInitialization(@postConstruct)

>> InitializingBean.afterPropertiesSet --> invokeInitMethod(init-method )

6)BeanPostProcessor.postProcessAfterInitialization

>> 單實例(容器初始化完成):SmartInitializingSingleton.afterSingletonsInstantiated

 

4. 應用

1)BeanFactoryPostProcessor

2)BeanPostProcessor:ApplicationContextAwareProcessor、InitDestroyAnnotationBeanPostProcessor、AutowiredAnnotationBeanPostProcessor、AOP

相關文章
相關標籤/搜索