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的三級緩存
是為了解決對象間循環(huán)依賴的問題