Spring IOC循环依赖问题
作者:互联网
A对象引用B对象
B对象引用A对象
spring中采用三级缓存来解决:
private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap(16);
简易代码:
public static void main(String[] args) {
HashMap hashMap = new HashMap();//缓存未赋值的对象 对应spring中的三级缓存
hashMap.put("aobj",new Aobj());
hashMap.put("bobj",new Bobj());
//相互依赖
Aobj aobj = (Aobj) hashMap.get("aobj");
Bobj bobj = (Bobj) hashMap.get("bobj");
aobj.setBobj(bobj);
bobj.setAobj(aobj);
System.out.println();
}
效果:
标签:依赖,bobj,Spring,aobj,Aobj,new,HashMap,IOC,hashMap 来源: https://blog.csdn.net/qq_33522040/article/details/100529865