{"record":{"id":"cf588be4014f65bb","repo":"spring-projects/spring-framework","slug":"can-t-determine-type-of-bean-with-name-targetbea","errorCode":null,"errorMessage":"Can't determine type of bean with name '{targetBeanName}'","messagePattern":"Can't determine type of bean with name '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java","lineNumber":73,"sourceCode":"\t * <p>This property is required.\n\t * @param methodName the name of the {@link Method} to locate\n\t */\n\tpublic void setMethodName(String methodName) {\n\t\tthis.methodName = methodName;\n\t}\n\n\t@Override\n\tpublic void setBeanFactory(BeanFactory beanFactory) {\n\t\tif (!StringUtils.hasText(this.targetBeanName)) {\n\t\t\tthrow new IllegalArgumentException(\"Property 'targetBeanName' is required\");\n\t\t}\n\t\tif (!StringUtils.hasText(this.methodName)) {\n\t\t\tthrow new IllegalArgumentException(\"Property 'methodName' is required\");\n\t\t}\n\n\t\tClass<?> beanClass = beanFactory.getType(this.targetBeanName);\n\t\tif (beanClass == null) {\n\t\t\tthrow new IllegalArgumentException(\"Can't determine type of bean with name '\" + this.targetBeanName + \"'\");\n\t\t}\n\t\tthis.method = BeanUtils.resolveSignature(this.methodName, beanClass);\n\n\t\tif (this.method == null) {\n\t\t\tthrow new IllegalArgumentException(\"Unable to locate method [\" + this.methodName +\n\t\t\t\t\t\"] on bean [\" + this.targetBeanName + \"]\");\n\t\t}\n\t}\n\n\n\t@Override\n\tpublic @Nullable Method getObject() throws Exception {\n\t\treturn this.method;\n\t}\n\n\t@Override\n\tpublic Class<Method> getObjectType() {\n\t\treturn Method.class;","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java#L55-L91","documentation":"After targetBeanName is set, setBeanFactory() calls beanFactory.getType(targetBeanName) (line 71) to learn the bean's class so it can resolve the method on it. getType returns null when the bean does not exist or its type cannot be determined (e.g. an unresolvable FactoryBean whose getObjectType() returns null). Spring then throws this IllegalArgumentException.","triggerScenarios":"targetBeanName refers to a bean that is not defined in the BeanFactory; the named bean is a FactoryBean whose object type is unknown at this early phase; the bean is in a child context not visible to the one creating the MethodLocatingFactoryBean.","commonSituations":"Typo in the bean name; the target bean lives in a different (sibling) context; the target is itself a FactoryBean that hasn't been initialized and returns null from getObjectType(); referencing a bean by alias that isn't registered.","solutions":["Verify the bean named by targetBeanName is actually defined in the same BeanFactory (check the bean id and any aliases)","If the target is a FactoryBean, ensure its getObjectType() can return a non-null class early (avoid lazy type resolution)","Confirm you are not splitting MethodLocatingFactoryBean and its target across parent/child contexts where the child cannot resolve the type"],"exampleFix":"// before\n<bean id=\"myMethod\" class=\"org.springframework.aop.config.MethodLocatingFactoryBean\">\n  <property name=\"targetBeanName\" value=\"misSpelledService\"/>\n  <property name=\"methodName\" value=\"doWork\"/>\n</bean>\n\n// after\n<bean id=\"myMethod\" class=\"org.springframework.aop.config.MethodLocatingFactoryBean\">\n  <property name=\"targetBeanName\" value=\"myService\"/>\n  <property name=\"methodName\" value=\"doWork\"/>\n</bean>","handlingStrategy":"validation","validationCode":"// Confirm the bean exists and its type is resolvable before defining the factory bean:\nif (beanFactory.getBeanNamesForType(...).length == 0 || beanFactory.getType(targetBeanName) == null) {\n  throw new IllegalStateException(\"Bean '\" + targetBeanName + \"' not resolvable\");\n}","typeGuard":"private static boolean beanTypeResolvable(BeanFactory bf, String name) {\n  return bf != null && StringUtils.hasText(name) && bf.getType(name) != null;\n}","tryCatchPattern":null,"preventionTips":["Keep MethodLocatingFactoryBean and its target bean in the same application context","For FactoryBean targets, ensure getObjectType() returns a non-null class without needing full initialization"],"tags":["spring-aop","config","factory-bean","bean-not-found"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}