Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'a': Requested bean is currently in creation: Is there an unresolvable circular reference?
/** Cache of singleton objects: bean name --> bean instance(缓存单例实例化对象的Map集合) */ privatefinal Map<String, Object> singletonObjects = new ConcurrentHashMap<String, Object>(64); /** Cache of singleton factories: bean name --> ObjectFactory(单例的工厂Bean缓存集合) */ privatefinal Map<String, ObjectFactory> singletonFactories = new HashMap<String, ObjectFactory>(16); /** Cache of early singleton objects: bean name --> bean instance(早期的单身对象缓存集合) */ privatefinal Map<String, Object> earlySingletonObjects = new HashMap<String, Object>(16); /** Set of registered singletons, containing the bean names in registration order(单例的实例化对象名称集合) */ privatefinal Set<String> registeredSingletons = new LinkedHashSet<String>(64); /** * 添加单例实例 * 解决循环引用的问题 * Add the given singleton factory for building the specified singleton * if necessary. * <p>To be called for eager registration of singletons, e.g. to be able to * resolve circular references. * @param beanName the name of the bean * @param singletonFactory the factory for the singleton object */ protectedvoidaddSingletonFactory(String beanName, ObjectFactory singletonFactory){ Assert.notNull(singletonFactory, "Singleton factory must not be null"); synchronized (this.singletonObjects) { if (!this.singletonObjects.containsKey(beanName)) { this.singletonFactories.put(beanName, singletonFactory); this.earlySingletonObjects.remove(beanName); this.registeredSingletons.add(beanName); } } }
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'a': Requested bean is currently in creation: Is there an unresolvable circular reference?