{"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":"exception","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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java#L50-L86","documentation":"Thrown by MethodLocatingFactoryBean.setBeanFactory() when the 'methodName' property is blank/null. This FactoryBean resolves a named Method on a target aspect bean; without a method name it has nothing to locate. Spring's <aop:config> parser populates methodName from the 'method' attribute of the advice element, so a blank value means that attribute was omitted or empty.","triggerScenarios":"Parsing an advice element like <aop:before method=\"\" pointcut=\"...\"/> inside <aop:aspect>, or programmatically constructing a MethodLocatingFactoryBean without calling setMethodName.","commonSituations":"Forgetting the 'method' attribute on <aop:before>/<aop:around>/etc. Typo leaving method=\"\". Programmatic bean-definition construction that skips setMethodName.","solutions":["Provide a non-empty 'method' attribute on each <aop:before>/<aop:after>/<aop:after-returning>/<aop:after-throwing>/<aop:around> element matching a public method on the aspect bean.","When using MethodLocatingFactoryBean programmatically, call setMethodName(\"adviceMethodName\") before initialization."],"exampleFix":"<!-- before -->\n<aop:config>\n  <aop:aspect ref=\"auditBean\">\n    <aop:before method=\"\" pointcut=\"execution(* *(..))\"/>\n  </aop:aspect>\n</aop:config>\n<!-- after -->\n<aop:config>\n  <aop:aspect ref=\"auditBean\">\n    <aop:before method=\"log\" pointcut=\"execution(* *(..))\"/>\n  </aop:aspect>\n</aop:config>","handlingStrategy":"validation","validationCode":"import org.w3c.dom.Element;\nimport java.util.Set;\n\nvoid ensureMethodAttrSet(Element adviceElement) {\n  Set<String> adviceTags = Set.of(\"before\",\"after\",\"after-returning\",\"after-throwing\",\"around\");\n  if (adviceTags.contains(adviceElement.getLocalName())\n      && (adviceElement.getAttribute(\"method\") == null || adviceElement.getAttribute(\"method\").isBlank()))\n    throw new IllegalArgumentException(\"<aop:\" + adviceElement.getLocalName() + \"> requires a non-empty 'method' attribute\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set method=\"adviceMethodName\" on every <aop:*> advice element.","Add an XML-schema-based CI check for <aop:config> documents.","Prefer annotation-based @Aspect to avoid forgetting XML attributes."],"tags":["spring-aop","xml-config","factory-bean","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}