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

  1. Add <property name="methodName" value="doWork"/> or call factoryBean.setMethodName("doWork")
  2. 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)
  3. 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

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


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)