Spring 是如何默认开启循环依赖的?如何关闭支持循环依赖?
@Autowired和@Resource区别
@Autowired由AutowiredAnnotationBeanPostProcessor后置处理器解析,@Resource由CommonAnnotationBeanPostProcessor解析
循环依赖的实现
/** Cache of singleton objects: bean name to bean instance. */
private final Map<String, Object> singletonObjects = new ConcurrentHashMap<>(256);
/** Cache of singleton factories: bean name to ObjectFactory. */
private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap<>(16);
/** Cache of early singleton objects: bean name to bean instance. */
private final Map<String, Object> earlySingletonObjects = new HashMap<>(16);singletonObjects 单例池 Spring容器 一级缓存 存储的是bean
singletonFactories 工厂 二级缓存 存储的是对象(半成品的bean)
earlySingletonObjects 三级缓存
三级缓存put一个从二级缓存中生产出来的一个对象
为什么需要三级缓存?因为防止重复创建,提高效率