spring-projects/spring-framework · error · IllegalArgumentException
Property 'methodName' is required
Error message
Property 'methodName' is required
What it means
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.
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
Example fix
// before <bean id="myMethod" class="org.springframework.aop.config.MethodLocatingFactoryBean"> <property name="targetBeanName" value="myService"/> </bean> // after <bean id="myMethod" class="org.springframework.aop.config.MethodLocatingFactoryBean"> <property name="targetBeanName" value="myService"/> <property name="methodName" value="doWork"/> </bean>
Defensive patterns
Strategy: validation
Validate before calling
if (!StringUtils.hasText(factoryBean.getMethodName())) {
throw new IllegalStateException("methodName not set on MethodLocatingFactoryBean");
} Type guard
private static boolean hasMethodName(MethodLocatingFactoryBean fb) {
return fb != null && StringUtils.hasText(fb.getMethodName());
} Prevention
- Use a builder/helper that forces both targetBeanName and methodName to be supplied together
- Validate config in a @PostConstruct or context-load test
When it happens
Trigger: A MethodLocatingFactoryBean definition that sets targetBeanName but omits methodName (or sets it to a blank string). The !StringUtils.hasText check at line 67 fires.
Common situations: 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.
Related errors
- Property 'targetBeanName' is required
- Can't determine type of bean with name
- Property 'target' is required
- Unable to locate method
- Both 'constructorArgs' and 'constructorArgTypes' need to be…
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/03effb96035e67b3.
Report an issue: GitHub.
Appendix: 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 69bf83ad71)