{"record":{"id":"03effb96035e67b3","repo":"spring-projects/spring-framework","slug":"property-methodname-is-required","errorCode":null,"errorMessage":"Property 'methodName' is required","messagePattern":"Property 'methodName' is required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java","lineNumber":68,"sourceCode":"\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\n\t@Override\n\tpublic @Nullable Method getObject() throws Exception {\n\t\treturn this.method;","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java#L50-L86","documentation":"MethodLocatingFactoryBean needs the name of the Method to locate on the target bean's class. 'methodName' is the second required property (checked at line 67); it is passed to BeanUtils.resolveSignature to resolve the Method. Thrown from setBeanFactory() during context startup, so the bean fails to initialize.","triggerScenarios":"A MethodLocatingFactoryBean definition that sets targetBeanName but omits methodName (or sets it to a blank string). The !StringUtils.hasText check at line 67 fires.","commonSituations":"XML bean definition missing the <property name=\"methodName\" .../> entry; programmatic config where setMethodName() was forgotten; refactoring that removed the method name while leaving the bean definition in place.","solutions":["Add <property name=\"methodName\" value=\"doWork\"/> or call factoryBean.setMethodName(\"doWork\")","Make sure the method name is spelled exactly as declared on the target bean's class (overloads are handled by resolveSignature, but the name itself must exist)","Pair methodName with targetBeanName on every MethodLocatingFactoryBean definition"],"exampleFix":"// before\n<bean id=\"myMethod\" class=\"org.springframework.aop.config.MethodLocatingFactoryBean\">\n  <property name=\"targetBeanName\" value=\"myService\"/>\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":"if (!StringUtils.hasText(factoryBean.getMethodName())) {\n  throw new IllegalStateException(\"methodName not set on MethodLocatingFactoryBean\");\n}","typeGuard":"private static boolean hasMethodName(MethodLocatingFactoryBean fb) {\n  return fb != null && StringUtils.hasText(fb.getMethodName());\n}","tryCatchPattern":null,"preventionTips":["Use a builder/helper that forces both targetBeanName and methodName to be supplied together","Validate config in a @PostConstruct or context-load test"],"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"}