{"record":{"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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java#L289-L325","documentation":"Thrown as FactoryBeanNotInitializedException by ProxyFactoryBean.getSingletonInstance when autodetectInterfaces is true (the default), no interfaces are explicitly set, proxyTargetClass is false, and getTargetClass() returns null. The factory cannot infer which interfaces to proxy because no target is set yet, so initialization aborts.","triggerScenarios":"A ProxyFactoryBean bean configured with interceptorNames but no target/targetName/targetSource and no proxyInterfaces, fetched from the BeanFactory before a target is available. Lines 303-308: autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass() && getTargetClass() == null.","commonSituations":"XML/@Configuration ProxyFactoryBean where the target property was forgotten or the target bean name was misspelled; circular-dependency scenarios where getObject() is called before the target bean exists; using interceptorNames with the target as last entry but the bean type cannot be determined.","solutions":["Set the target: <property name=\"target\" ref=\"myServiceBean\"/> or setTargetName(\"myServiceBean\").","Or set explicit interfaces: <property name=\"proxyInterfaces\" value=\"com.example.MyService\"/>.","Or set proxyTargetClass=true so the factory builds a class proxy without needing interfaces.","Check for typos in targetName and circular-dependency ordering issues that leave the target unresolved."],"exampleFix":"<!-- before -->\n<bean id=\"service\" class=\"...ProxyFactoryBean\">\n  <property name=\"interceptorNames\" value=\"loggingAdvice\"/>\n</bean>\n\n<!-- after -->\n<bean id=\"service\" class=\"...ProxyFactoryBean\">\n  <property name=\"target\" ref=\"serviceImpl\"/>\n  <property name=\"interceptorNames\" value=\"loggingAdvice\"/>\n</bean>","handlingStrategy":"validation","validationCode":"// Sanity-check before relying on getObjectType()/getObject()\nif (pfb.isAutodetectInterfaces() && pfb.getProxiedInterfaces().length == 0\n    && !pfb.isProxyTargetClass() && pfb.getTargetClass() == null) {\n  throw new IllegalStateException(\"ProxyFactoryBean missing target/interfaces/proxyTargetClass\");\n}","typeGuard":"static boolean proxyFactoryBeanReady(ProxyFactoryBean fb) {\n  return fb.getTarget() != null || fb.getTargetSource() != null\n      || fb.getProxiedInterfaces().length > 0 || fb.isProxyTargetClass();\n}","tryCatchPattern":"try { Object p = pfb.getObject(); }\ncatch (FactoryBeanNotInitializedException e) {\n  if (e.getMessage().contains(\"Cannot determine target class\")) { /* set target or interfaces */ }\n  throw e;\n}","preventionTips":["Always set target/targetName/targetSource or proxyInterfaces on ProxyFactoryBean.","Set proxyTargetClass=true when you want a class proxy without specifying interfaces.","Verify bean names for typos; use IDE 'find usage' on the target bean."],"tags":["spring-aop","proxyfactorybean","configuration","factorybean"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}