{"record":{"id":"1c25e48f1486e173","repo":"spring-projects/spring-framework","slug":"property-targetbeanname-is-required","errorCode":null,"errorMessage":"Property 'targetBeanName' is required","messagePattern":"Property 'targetBeanName' is required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java","lineNumber":65,"sourceCode":"\t * @param targetBeanName the name of the bean to locate the {@link Method} on\n\t */\n\tpublic void setTargetBeanName(String targetBeanName) {\n\t\tthis.targetBeanName = targetBeanName;\n\t}\n\n\t/**\n\t * Set the name of the {@link Method} to locate.\n\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","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java#L47-L83","documentation":"MethodLocatingFactoryBean is a FactoryBean that resolves a java.lang.reflect.Method from a target bean during BeanFactory initialization. The 'targetBeanName' property names which bean to introspect; without it there is no class to look the method up on. The exception is thrown from setBeanFactory() (the BeanFactoryAware callback, line 64) so the failure surfaces at application-context startup.","triggerScenarios":"Defining a MethodLocatingFactoryBean bean (XML, Java @Bean, or GenericBeanDefinition) and never calling setTargetBeanName(...) before the context initializes it. The check is !StringUtils.hasText(this.targetBeanName), so null, empty, or whitespace-only all trip it.","commonSituations":"XML <bean class=\"...MethodLocatingFactoryBean\"> missing the <property name=\"targetBeanName\" .../> element; a typo in the property name; a refactored config that accidentally dropped the setter call; copy-pasting a bean definition without the required properties.","solutions":["Add <property name=\"targetBeanName\" value=\"myServiceBean\"/> (XML) or call factoryBean.setTargetBeanName(\"myServiceBean\") so the bean has a non-blank name","Confirm the bean name you supply matches an actual bean id/name in the same ApplicationContext","Run a quick grep on the config for MethodLocatingFactoryBean and verify every occurrence sets both targetBeanName and methodName"],"exampleFix":"// before\n<bean id=\"myMethod\" class=\"org.springframework.aop.config.MethodLocatingFactoryBean\">\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":"// Before relying on the factory bean, ensure the property is set:\nif (!StringUtils.hasText(factoryBean.getTargetBeanName())) {\n  throw new IllegalStateException(\"targetBeanName not set on MethodLocatingFactoryBean\");\n}","typeGuard":"private static boolean hasTargetBeanName(MethodLocatingFactoryBean fb) {\n  return fb != null && StringUtils.hasText(fb.getTargetBeanName());\n}","tryCatchPattern":null,"preventionTips":["Centralize MethodLocatingFactoryBean creation in a helper that requires both targetBeanName and methodName as parameters","Add a unit test that loads the relevant application context to catch missing properties at build time"],"tags":["spring-aop","config","factory-bean","missing-property"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}