spring-projects/spring-framework · error · IllegalArgumentException
Mapped value [
Error message
Mapped value [
What it means
Thrown as an IllegalArgumentException by CustomScopeConfigurer.postProcessBeanFactory when a value in its scopes map is not an instance of Scope, a Class assignable to Scope, or a String naming a Scope class. The configurer (a BeanFactoryPostProcessor) registers custom scopes from a map keyed by scope name; any other value type is rejected with the offending value and key in the message.
Source
Thrown at spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java:113
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (this.scopes != null) {
this.scopes.forEach((scopeKey, value) -> {
if (value instanceof Scope scope) {
beanFactory.registerScope(scopeKey, scope);
}
else if (value instanceof Class<?> scopeClass) {
Assert.isAssignable(Scope.class, scopeClass, "Invalid scope class");
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
}
else if (value instanceof String scopeClassName) {
Class<?> scopeClass = ClassUtils.resolveClassName(scopeClassName, this.beanClassLoader);
Assert.isAssignable(Scope.class, scopeClass, "Invalid scope class");
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
}
else {
throw new IllegalArgumentException("Mapped value [" + value + "] for scope key [" +
scopeKey + "] is not an instance of required type [" + Scope.class.getName() +
"] or a corresponding Class or String value indicating a Scope implementation");
}
});
}
}
}
View on GitHub (pinned to 69bf83ad71)
Solutions
- Ensure each scope map value is a Scope instance, a Class<? extends Scope>, or a String holding the FQN of a Scope implementation.
- Point the map value at the actual Scope bean (e.g. SimpleThreadScope, RequestScope) rather than a scope name or unrelated bean.
- If using XML, fix the <entry> so value-ref points at the Scope bean, or use key='scopeName' value='fqcn'.
- Register the scope programmatically with beanFactory.registerScope(name, scopeInstance) to bypass the map entirely.
- Add an assertion in test code that every map value is assignable to Scope before calling setScopes.
Example fix
<!-- before: value is a scope name String, not a Scope -->
<bean class='o.s.beans.factory.config.CustomScopeConfigurer'>
<property name='scopes'>
<map><entry key='thread' value='thread'/></map>
</property>
</bean>
<!-- after: value is a Scope bean reference -->
<bean class='o.s.beans.factory.config.CustomScopeConfigurer'>
<property name='scopes'>
<map>
<entry key='thread' value-ref='threadScope'/>
</map>
</property>
</bean>
<bean id='threadScope' class='o.s.context.support.SimpleThreadScope'/> Defensive patterns
Strategy: validation
Validate before calling
Map<String, ?> scopes = customScopeConfigurer.getScopes();
scopes.forEach((k, v) -> {
boolean ok = v instanceof Scope || v instanceof Class<?> c && Scope.class.isAssignableFrom(c)
|| v instanceof String;
if (!ok) throw new IllegalArgumentException("Invalid scope value for key " + k + ": " + v);
}); Type guard
boolean isValidScopeValue(Object v) {
return v instanceof Scope ||
(v instanceof Class<?> c && Scope.class.isAssignableFrom(c)) ||
v instanceof String;
} Prevention
- Use beanFactory.registerScope(name, scopeInstance) directly to avoid the map.
- Point CustomScopeConfigurer map values at Scope bean references, not names.
- Lint XML scope-config entries for value-ref correctness.
- Add a config sanity test that asserts each scope value is a Scope/Class/String.
When it happens
Trigger: Setting CustomScopeConfigurer.setScopes(map) with a map entry whose value is an Integer, a non-Scope bean, a Class that is not assignable to Scope, or a String that resolves to a non-Scope class. postProcessBeanFactory iterates the map and throws on the first unsupported value type.
Common situations: XML <bean class='...CustomScopeConfigurer'> with a <map> entry whose value-ref points at a non-Scope bean; @Bean method building the scopes map with the wrong value; passing a scope name as value instead of the Scope instance; typo in the scope class FQN string; reflective bean copy that loses type info.
Related errors
- CustomAutowireConfigurer needs to operate on a DefaultListab
- Invalid value [{}] for custom qualifier type: needs to be Cl
- Qualifier type [{}] needs to be annotation type
- Value annotation must have a value attribute
- Cannot invoke instance method without factoryBeanName:
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/ba0c9f83bd75c3ed.
Report an issue: GitHub.