org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#populateBean 填充实例
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry#getSingleton(java.lang.String)
Spring容器使用Map存储对象,在Spring中存在三级缓存,singletonObjects存放完整的bean对象。
/** Cache of singleton objects: bean name --> bean instance */
private final Map<String, Object> singletonObjects = new ConcurrentHashMap<>(256);
/** Cache of singleton factories: bean name --> ObjectFactory */
private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap<>(16);
/** Cache of early singleton objects: bean name --> bean instance */
private final Map<String, Object> earlySingletonObjects = new HashMap<>(16);
6W2H
一级缓存 singletonObjects。存放属性已赋值,初始化后的单例对象
二级缓存 earlySingletonObjects 存放已实例化,还未做属性赋值操作的单例
三级缓存 singletonFactories 单例Bean的工厂实例
三级缓存
Spring的三级缓存
是为了解决对象间循环依赖的问题