{"id":"dfb991d168925f14","repo":"spring-projects/spring-framework","slug":"does-not-support-circular-references","errorCode":null,"errorMessage":"{} does not support circular references","messagePattern":"(.+?) does not support circular references","errorType":"exception","errorClass":"FactoryBeanNotInitializedException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java","lineNumber":164,"sourceCode":"\tpublic final T getObject() throws Exception {\n\t\tif (isSingleton()) {\n\t\t\tT instance = this.singletonInstance;\n\t\t\treturn (instance != null ? instance : getEarlySingletonInstance());\n\t\t}\n\t\telse {\n\t\t\treturn createInstance();\n\t\t}\n\t}\n\n\t/**\n\t * Determine an 'early singleton' instance, exposed in case of a\n\t * circular reference. Not called in a non-circular scenario.\n\t */\n\t@SuppressWarnings(\"unchecked\")\n\tprivate T getEarlySingletonInstance() {\n\t\tClass<?>[] ifcs = getEarlySingletonInterfaces();\n\t\tif (ifcs == null) {\n\t\t\tthrow new FactoryBeanNotInitializedException(\n\t\t\t\t\tgetClass().getName() + \" does not support circular references\");\n\t\t}\n\t\tif (this.earlySingletonInstance == null) {\n\t\t\tthis.earlySingletonInstance = (T) Proxy.newProxyInstance(\n\t\t\t\t\tthis.beanClassLoader, ifcs, new EarlySingletonInvocationHandler());\n\t\t}\n\t\treturn this.earlySingletonInstance;\n\t}\n\n\t/**\n\t * Expose the singleton instance (for access through the 'early singleton' proxy).\n\t * @return the singleton instance that this FactoryBean holds\n\t * @throws IllegalStateException if the singleton instance is not initialized\n\t */\n\tprivate T getSingletonInstance() throws IllegalStateException {\n\t\tT instance = this.singletonInstance;\n\t\tAssert.state(instance != null, \"Singleton instance not initialized yet\");\n\t\treturn instance;","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java#L146-L182","documentation":"AbstractFactoryBean.getObject, when involved in a circular reference, exposes an early singleton proxy via getEarlySingletonInstance; that requires getEarlySingletonInterfaces() to return the interfaces to proxy. The base implementation returns null, so a FactoryBean that does not override getEarlySingletonInterfaces cannot participate in circular references and throws FactoryBeanNotInitializedException.","triggerScenarios":"A custom FactoryBean (extending AbstractFactoryBean) is part of a bean reference cycle, but the subclass does not override getEarlySingletonInterfaces() to declare which interfaces the early proxy should expose.","commonSituations":"Two beans mutually depending on each other where at least one is a FactoryBean that leaves getEarlySingletonInterfaces at its default (null); a refactor introduces a cycle involving a FactoryBean.","solutions":["Override getEarlySingletonInterfaces() in your FactoryBean to return the interface(s) the early proxy should implement.","Break the circular dependency (extract a shared collaborator, use @Lazy, setter injection, or restructure).","If circular references are not needed, ensure no cycle exists - the error itself confirms a cycle is present."],"exampleFix":"// before\npublic class MyFactoryBean extends AbstractFactoryBean<MyService> {\n  // getEarlySingletonInterfaces() not overridden\n}\n// after\n@Override\nprotected Class<?>[] getEarlySingletonInterfaces() {\n  return new Class<?>[] { MyService.class };\n}","handlingStrategy":"validation","validationCode":"if (bean instanceof FactoryBean<?> fb && fb instanceof AbstractFactoryBean<?> afb) {\n  if (afb.getEarlySingletonInterfaces() == null) {\n    log.warn(\"FactoryBean {} cannot participate in circular references\", fb.getClass());\n  }\n}","typeGuard":"boolean supportsCircularRefs(AbstractFactoryBean<?> fb) {\n  try { return fb.getEarlySingletonInterfaces() != null; }\n  catch (Throwable t) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Override getEarlySingletonInterfaces() in custom AbstractFactoryBean subclasses.","Design away circular dependencies involving FactoryBeans via @Lazy or restructuring.","Add a test that asserts FactoryBeans in cyclic graphs expose early-singleton interfaces."],"tags":["spring","factorybean","circular-reference","bean-creation"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}