Spring生命周期
2023-02-24 17:08:40 0 举报
spring生命周期
作者其他创作
大纲/内容
开始初始化容器
AbstractApplicationContext
invokeBeanFactoryPostProcessors(beanFactory); //会调用postProcessBeanFactory()方法
ApplicationContext xmlAppContext = new ClassPathXmlApplicationContext(\"beans.xml\");
只有PersonBean才会调用到这里(Bean级别的)
applyBeanPostProcessorsBeforeInitialization();
参考类
生成BeanDefinition缓存起来
BeanFactory处理和注册BenaPostProcess
preInstantiateSingletons(){ for(beanName : beanNames) { getBean(beanName); }}
DefaultSingletonBeanRegistry{ singletonObject; singleTonFactories; earlySingleTonObjects; protected void addSingleton();}
destroy(); //DisposibleBean接口方法
PersonBeanMyBeanDefinitionRegistryPostProcessor
PersonBean.class
postProcessBeanFactory(beanFactory);
initializeBean();
createBean
finishBeanFactoryInitialization
DefaultListableBeanFactory implements BeanDefinitionRegistry{ beanDefinitionMap; beanDefinitionNames; registerBeanDefinition();}
//ConfigurationClassPostProcessor.javainvokeBeanDefinitionRegistryPostProcessors{ (ConfigurationClassPostProcessor)BeanDefinitionRegistryPostProcessor.postProcessBeanDefinitionRegistry();}
DefaultListableBeanFactory.registerBeanDefinition();
addsingleton()
//ConfigurationClassPostProcessor 进来后调用的ImportSelector.selectImports();ImportBeanDefinitionRegistrar.registerBeanDefinitions();//@Bean对应的BeanDefinition也是在这里被处理的参考
applyBeanPostProcessorsAfterInitialization();
registerBeanPostProcessors(beanFactory); //getBean(beanPostProcessor)
xmlAppContext).registerShutdownHook()
destoryBean
AbstractAutowireCapableBeanFactory
invokeAwareMethods(); //BeanFactoryAware
invokeInitMethods(); //InitializingBean.afterPropertiesSet();
populateBean();
所有Bean都要走一遍(容器级别的)
收藏
0 条评论
下一页