spring singleton bean circular reference solution
2021-02-01 11:29:24 3 举报
spring singleton 单例bean的循环依赖核心设计和流程
作者其他创作
大纲/内容
return bean
get
bean cache level 2
singletonFactoriesHashMap(16)
earlySingletonObjectsHashMap(16)
DI operation circular ref
bean cache level 1
if null
afterSingletonCreationthis.singletonsCurrentlyInCreation.remove(beanName)
doCreateBean
populateBeanDI operation
put bean into earlySingletonObjects
bean cache level 3
remove from singletonFactories
mark that bean is creating
DI
initializeBeanAOP operation and get final bean
beforeSingletonCreation(this.singletonsCurrentlyInCreation.add(beanName))
singletonsCurrentlyInCreationSet(16)
getBean
addSingletonthis.singletonObjects.font color=\"#009900\
get singleton bean(singleton)
create bean
addSingletonFactoryif (!this.singletonObjects.containsKey(beanName)) { this.earlySingletonObjects.remove(beanName); this.singletonFactories.font color=\"#4d9900\
check if singleton is currentlyin creation
singletonObjectsConcurrentHashMap(256)
in creating
0 条评论
下一页