参考:https://blog.csdn.net/weixin_45674354/article/details/105557240
Spring内部维护了三个Map,也就是我们通常说的三级缓存,位置在DefaultSingletonBeanRegistry
private final Map<String, Object> singletonObjects = new ConcurrentHashMap(256); private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap(16); private final Map<String, Object> earlySingletonObjects = new HashMap(16);
创建a发现singletonObjects 没有,然后创建a,并提前暴露,放到singletonFactories 中,然后依赖注入,发现需要b
发现singletonObjects 没有,然后创建b,并提前暴露,放到singletonFactories 中,然后依赖注入,发现需要a,a已经提前暴露,注入a,放到earlySingletonObjects ,b创建完毕,然后a创建完毕
其实就是类似two sum的思想。