spring-projects/spring-framework · error · IllegalArgumentException
Property 'methodName' is required
Error message
Property 'methodName' is required
What it means
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.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java:68
this.targetBeanName = targetBeanName;
}
/**
* Set the name of the {@link Method} to locate.
* <p>This property is required.
* @param methodName the name of the {@link Method} to locate
*/
public void setMethodName(String methodName) {
this.methodName = methodName;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) {
if (!StringUtils.hasText(this.targetBeanName)) {
throw new IllegalArgumentException("Property 'targetBeanName' is required");
}
if (!StringUtils.hasText(this.methodName)) {
throw new IllegalArgumentException("Property 'methodName' is required");
}
Class<?> beanClass = beanFactory.getType(this.targetBeanName);
if (beanClass == null) {
throw new IllegalArgumentException("Can't determine type of bean with name '" + this.targetBeanName + "'");
}
this.method = BeanUtils.resolveSignature(this.methodName, beanClass);
if (this.method == null) {
throw new IllegalArgumentException("Unable to locate method [" + this.methodName +
"] on bean [" + this.targetBeanName + "]");
}
}
@Override
public @Nullable Method getObject() throws Exception {
return this.method;View on GitHub (pinned to e8729d0438)
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.
Example fix
<!-- before -->
<aop:config>
<aop:aspect ref="auditBean">
<aop:before method="" pointcut="execution(* *(..))"/>
</aop:aspect>
</aop:config>
<!-- after -->
<aop:config>
<aop:aspect ref="auditBean">
<aop:before method="log" pointcut="execution(* *(..))"/>
</aop:aspect>
</aop:config> Defensive patterns
Strategy: validation
Validate before calling
import org.w3c.dom.Element;
import java.util.Set;
void ensureMethodAttrSet(Element adviceElement) {
Set<String> adviceTags = Set.of("before","after","after-returning","after-throwing","around");
if (adviceTags.contains(adviceElement.getLocalName())
&& (adviceElement.getAttribute("method") == null || adviceElement.getAttribute("method").isBlank()))
throw new IllegalArgumentException("<aop:" + adviceElement.getLocalName() + "> requires a non-empty 'method' attribute");
} Prevention
- 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.
When it happens
Trigger: Parsing an advice element like <aop:before method="" pointcut="..."/> inside <aop:aspect>, or programmatically constructing a MethodLocatingFactoryBean without calling setMethodName.
Common situations: Forgetting the 'method' attribute on <aop:before>/<aop:around>/etc. Typo leaving method="". Programmatic bean-definition construction that skips setMethodName.
Related errors
- Property 'targetBeanName' is required
- Unknown advice kind [{}].
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Only afterReturning advice can be used to bind a return valu
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/03effb96035e67b3.json.
Report an issue: GitHub.