{"id":"a039aca4ac1f35fe","repo":"spring-projects/spring-framework","slug":"cannot-determine-target-class-for-proxy","errorCode":null,"errorMessage":"Cannot determine target class for proxy","messagePattern":"Cannot determine target class for proxy","errorType":"exception","errorClass":"FactoryBeanNotInitializedException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java","lineNumber":307,"sourceCode":"\t@Override\n\tpublic boolean isSingleton() {\n\t\treturn this.singleton;\n\t}\n\n\n\t/**\n\t * Return the singleton instance of this class's proxy object,\n\t * lazily creating it if it hasn't been created already.\n\t * @return the shared singleton proxy\n\t */\n\tprivate synchronized Object getSingletonInstance() {\n\t\tif (this.singletonInstance == null) {\n\t\t\tthis.targetSource = freshTargetSource();\n\t\t\tif (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) {\n\t\t\t\t// Rely on AOP infrastructure to tell us what interfaces to proxy.\n\t\t\t\tClass<?> targetClass = getTargetClass();\n\t\t\t\tif (targetClass == null) {\n\t\t\t\t\tthrow new FactoryBeanNotInitializedException(\"Cannot determine target class for proxy\");\n\t\t\t\t}\n\t\t\t\tsetInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));\n\t\t\t}\n\t\t\t// Initialize the shared singleton instance.\n\t\t\tsuper.setFrozen(this.freezeProxy);\n\t\t\tthis.singletonInstance = getProxy(createAopProxy());\n\t\t}\n\t\treturn this.singletonInstance;\n\t}\n\n\t/**\n\t * Create a new prototype instance of this class's created proxy object,\n\t * backed by an independent AdvisedSupport configuration.\n\t * @return a totally independent proxy, whose advice we may manipulate in isolation\n\t */\n\tprivate synchronized Object newPrototypeInstance() {\n\t\t// In the case of a prototype, we need to give the proxy\n\t\t// an independent instance of the configuration.","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java#L289-L325","documentation":"In ProxyFactoryBean.getSingletonInstance(), when interfaces must be auto-detected (autodetectInterfaces=true, no explicit interfaces, not proxyTargetClass) and getTargetClass() returns null, Spring cannot decide which interfaces the JDK proxy should expose. It throws FactoryBeanNotInitializedException because the target class is unknown at the moment of proxy creation.","triggerScenarios":"ProxyFactoryBean configured with interceptorNames but neither a target nor a targetSource set, AND not in proxyTargetClass mode, AND autodetectInterfaces is left on (default). Also happens when the target bean is itself a FactoryBean that has not been initialized yet.","commonSituations":"XML/config lists only interceptorNames and omits 'target'/'targetName'; pointing targetName at a prototype FactoryBean whose type cannot be resolved eagerly; misordering bean definitions so the target is not yet available; circular bean references during initialization.","solutions":["Set an explicit target (target or targetName property) or explicit 'proxyInterfaces' on the ProxyFactoryBean.","Set proxyTargetClass=true if you want a CGLIB proxy of a concrete class.","Ensure the referenced target bean is resolvable at ProxyFactoryBean initialization time (avoid circular dependencies)."],"exampleFix":"// before\n<bean class=\"...ProxyFactoryBean\">\n  <property name=\"interceptorNames\" value=\"myAdvice\"/>\n</bean>\n\n// after\n<bean class=\"...ProxyFactoryBean\">\n  <property name=\"target\" ref=\"myService\"/>\n  <property name=\"interceptorNames\" value=\"myAdvice\"/>\n</bean>","handlingStrategy":"validation","validationCode":"// Before relying on the FactoryBean, ensure target/interface is resolvable\nif (proxyFactoryBean.getTargetSource() == null\n        && proxyFactoryBean.getTarget() == null\n        && proxyFactoryBean.getProxiedInterfaces().length == 0\n        && !proxyFactoryBean.isProxyTargetClass()) {\n    throw new IllegalStateException(\"ProxyFactoryBean needs a target, targetName, proxyInterfaces, or proxyTargetClass=true\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set target/targetName or proxyInterfaces on ProxyFactoryBean.","Set proxyTargetClass=true to skip interface auto-detection.","Avoid pointing targetName at another FactoryBean that resolves lazily."],"tags":["aop","proxy-factory-bean","target","initialization"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}