getBean(xxx)
2021-09-25 23:37:57 0 举报
bean实例化过程
作者其他创作
大纲/内容
if bean != null
refresh()
实例化deptBean
bean = getSingleton()会调用三级缓存的getobject()
mbd.isSingleton()
在AbstractAutoProxy中的getEarlyBeanReference()中会获取早期创建的bean暴露的引用并创建代理
循环依赖
放入第三级缓存(singletonFactories),包装当前object泛型对象为SmartInstantiationAwareBeanPostProcessor,且getObject()关联getEarlyBeanReference(xxx)
将bean移入一级缓存(singletonObjects)
实例化bean
将当前bean移除singletonsCurrentlyInCreation集合
false
....
PostProcessor.postProcessBeforeInitialization
1. 当前bean有DestroyMethod;2. 存在DestructionAwareBeanPostProcessors;3. 当前bean需要Destruction;
createBean()
将当前bean放入singletonsCurrentlyInCreation集合
PostProcessor.postProcessAfterInitialization
感知容器对象BeanNameAware;BeanClassLoaderAware;BeanFactoryAware;
final RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation()
finishBeanFactoryInitialization(beanFactory)
return beanInstance;
用来扫描收集当前bean中的注解,并且合并到当前beanDefinition中
true
singletonFactories.getObject()调用SmartInstantiationAwareBeanPostProcessor.getEarlyBeanReference(xxx),获取提前暴露的bean引用,这里有可能创建代理(org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#getEarlyBeanReference)
返回bean
调用InitializingBean.afterPropertiesSet()或自定义InitMethod
0 条评论
下一页