spring-projects/spring-framework · error · IllegalArgumentException
Can't determine type of bean with name '{}'
Error message
Can't determine type of bean with name '{}' What it means
Thrown by MethodLocatingFactoryBean.setBeanFactory when BeanFactory.getType(targetBeanName) returns null, meaning the container cannot resolve a concrete type for the named bean at FactoryBean initialization time. Spring throws this because it needs a real Class to reflectively locate the target method that this FactoryBean is meant to expose. The error surfaces during context startup (bean initialization), not at runtime use of the located Method.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java:73
* <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;
}
@Override
public Class<Method> getObjectType() {
return Method.class;View on GitHub (pinned to e8729d0438)
Solutions
- Verify the exact spelling and case of 'targetBeanName' against the bean id in the same application context.
- Ensure the referenced bean is a concrete bean definition (not abstract) and is registered in the context that owns the MethodLocatingFactoryBean.
- If the target is a FactoryBean, confirm its getObjectType() returns a non-null Class at FactoryBean initialization time; implement/fix getObjectType() if it lazily returns null.
- Resolve any circular-dependency or parent-context issues that prevent type resolution by marking the target non-lazy or restructuring the dependency graph.
Example fix
// before <bean id="methodLocator" class="org.springframework.aop.config.MethodLocatingFactoryBean"> <property name="targetBeanName" value="servcie"/> <!-- typo --> <property name="methodName" value="doWork"/> </bean> // after <bean id="methodLocator" class="org.springframework.aop.config.MethodLocatingFactoryBean"> <property name="targetBeanName" value="service"/> <!-- matches real bean id --> <property name="methodName" value="doWork"/> </bean>
Defensive patterns
Strategy: validation
Validate before calling
BeanFactory bf = ...; String name = "myService";
Class<?> type = bf.getType(name);
if (type == null) {
throw new IllegalStateException(
"Cannot resolve type for bean '" + name + "'; fix the bean definition before wiring MethodLocatingFactoryBean");
} Prevention
- Keep bean ids in a shared constant or enum to avoid typo drift between the bean and its MethodLocatingFactoryBean reference.
- If the target is a FactoryBean, implement getObjectType() to return a concrete Class even before getObject() runs.
- Wire MethodLocatingFactoryBean beans in the same context that owns the target bean to avoid parent/child resolution gaps.
When it happens
Trigger: Configuring a <aop:aspect> or MethodLocatingFactoryBean in XML where the 'targetBeanName' property refers to a bean that is itself an untyped FactoryBean whose getObjectType() returns null, a bean definition that has not been loaded/registered, or a bean name typo. Also triggered when the bean is a scoped proxy whose type cannot be statically determined.
Common situations: Migrating XML AOP config and misspelling the target bean name; pointing at an abstract bean or parent bean definition that never gets a concrete type; referencing a FactoryBean (e.g. a third-party one) that does not implement getObjectType() before getObject() runs; circular dependencies that prevent type resolution at the point setBeanFactory fires.
Related errors
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Only afterReturning advice can be used to bind a return valu
- Only afterThrowing advice can be used to bind a thrown excep
- Advice method [{}] requires {} arguments to be bound by name
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/75afe47641fb4ca5.json.
Report an issue: GitHub.