Spring hook

2018-05-07  本文已影响0人  其_cd6b

书写顺序即为调用顺序


BeanDefinitionRegistryPostProcessor   ->postProcessBeanFactory(先调用BeanDefinitionRegistry的Factory后置处理器)

BeanFactoryPostProcessor ->postProcessBeanFactory(后调用普通的Factory后置处理器)

调用入口application ->refresh:

invokeBeanFactoryPostProcessors(beanFactory);


调用入口application ->refresh:

onRefresh();

getBean():

BeanPostProcessor ->实例化前后

postProcessBeforeInitialization(The bean will already be populated with propertyvalues)

postProcessAfterInitialization(The bean will already be populated with propertyvalues)

InstantiationAwareBeanPostProcessor

postProcessBeforeInstantiation ->动态代理

postProcessAfterInstantiation (Modify the state of the bean before properties are set)-> populateBean


postProcessPropertyValues(Before the factory applies them To the given bean)->populateBean ->AutowiredAnnotationBeanPostProcessor(autowire自动注入)


SmartInitializingSingleton->afterSingletonsInstantiated (所有non-lazy 初始化之后调用)

调用入口application ->refresh:

//Instantiateallremaining(non-lazy-init)singletons.

finishBeanFactoryInitialization(beanFactory);


Spring Bean 生命周期:

上一篇 下一篇

猜你喜欢

热点阅读