参考文章:Spring IOC 容器源码分析
第3小节中
// 提前曝光 bean 实例(raw bean),用于解决循环依赖
singletonObject = singletonFactory.getObject();
// 将 singletonObject 放入缓存中,并将 singletonFactory 从缓存中移除
this.earlySingletonObjects.put(beanName, singletonObject);
this.singletonFactories.remove(beanName);
实例化 A 这个bean以后【此时对象内部所有属性都为null】,已经将对象放入earlySingletonObjects【二级缓存】,并且将singletonFactories【三级缓存】中对应bean的factories删除
而后才会执行populateBean函数
而后再初始化B 这个bean时,里面的A 应该直接从 earlySingletonObjects【二级缓存】里面找啊,不应该从 singletonFactories【三级缓存】
相似问题