Skip to content

Spring IOC 循环依赖

akun edited this page Jul 18, 2019 · 1 revision

ioc中循环依赖的处理

spring处理循环依赖的数据基础

spring ioc只能处理singleton类型bean的循环依赖,无法处理prototype以及构造器循环依赖

    /** 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

    一级缓存

  • singletonFactories

    二级缓存

  • earlySingletonObjects

    三级缓存

test

Clone this wiki locally