spring-projects/spring-framework · error · IllegalArgumentException

Unable to locate method [{}] on bean [{}]

Error message

Unable to locate method [{}] on bean [{}]

What it means

Thrown by MethodLocatingFactoryBean.setBeanFactory after the bean type was resolved successfully but BeanUtils.resolveSignature(methodName, beanClass) returned null, meaning no method matching the given signature string could be found. resolveSignature accepts either a simple name or a fully-qualified signature with argument types, and a mismatch in either the name or the parameter type list yields this error. It is a configuration-time validation failure.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java:78

	}

	@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;
	}

	@Override
	public Class<Method> getObjectType() {
		return Method.class;
	}

	@Override
	public boolean isSingleton() {
		return true;

View on GitHub (pinned to e8729d0438)

Solutions

  1. Check the resolved bean's actual Class (enable debug logging on org.springframework.beans.BeanUtils) and confirm the method name exists on exactly that class.
  2. If overloaded, supply a full signature with argument types, e.g. 'doWork(int,java.lang.String)' using correct fully-qualified names (capitalize type names correctly).
  3. Verify parameter types: use fully-qualified class names and remember primitives are lowercase (int) while boxed types are java.lang.Integer.
  4. Rebuild/redeploy to ensure the class on the classpath matches the config (stale class file vs new config).

Example fix

// before
<property name="methodName" value="doWork(int,java.lang.string)"/>  // wrong casing

// after
<property name="methodName" value="doWork(int,java.lang.String)"/>  // correct FQN
Defensive patterns

Strategy: validation

Validate before calling

Class<?> beanClass = bf.getType("myService");
String methodName = "doWork(int,java.lang.String)";
if (org.springframework.beans.BeanUtils.resolveSignature(methodName, beanClass) == null) {
  throw new IllegalStateException(
    "Method '" + methodName + "' not found on " + beanClass + "; verify name and fully-qualified arg types");
}

Try / catch

try {
  // configure MethodLocatingFactoryBean
} catch (IllegalArgumentException ex) {
  if (ex.getMessage().contains("Unable to locate method")) {
    // log method + bean, point user at the renamed/missing method
  }
  throw ex;
}

Prevention

When it happens

Trigger: Calling setMethodName with a method that doesn't exist on the target bean's class; using a signature string with wrong fully-qualified parameter type names (e.g. 'java.lang.string' lowercase); overloads where resolveSignature cannot disambiguate without explicit args; the method exists only on a different class than the resolved bean type.

Common situations: Renaming a method in the target class but forgetting to update the XML AOP config; pointing at an interface-implementing class but specifying a method declared only on another implementation; copy-paste errors in overloaded method signatures; using primitive vs boxed type names inconsistently in the signature.

Related errors


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/adb362e61d893c5d.json. Report an issue: GitHub.