{"id":"3c76fe88532d41fa","repo":"spring-projects/spring-framework","slug":"mapped-value-for-scope-key-is-not-an-ins","errorCode":null,"errorMessage":"Mapped value [{}] for scope key [{}] is not an instance of required type [{}] or a corresponding Class or String value indicating a Scope implementation","messagePattern":"Mapped value \\[(.+?)\\] for scope key \\[(.+?)\\] is not an instance of required type \\[(.+?)\\] or a corresponding Class or String value indicating a Scope implementation","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java","lineNumber":113,"sourceCode":"\n\t@Override\n\tpublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {\n\t\tif (this.scopes != null) {\n\t\t\tthis.scopes.forEach((scopeKey, value) -> {\n\t\t\t\tif (value instanceof Scope scope) {\n\t\t\t\t\tbeanFactory.registerScope(scopeKey, scope);\n\t\t\t\t}\n\t\t\t\telse if (value instanceof Class<?> scopeClass) {\n\t\t\t\t\tAssert.isAssignable(Scope.class, scopeClass, \"Invalid scope class\");\n\t\t\t\t\tbeanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));\n\t\t\t\t}\n\t\t\t\telse if (value instanceof String scopeClassName) {\n\t\t\t\t\tClass<?> scopeClass = ClassUtils.resolveClassName(scopeClassName, this.beanClassLoader);\n\t\t\t\t\tAssert.isAssignable(Scope.class, scopeClass, \"Invalid scope class\");\n\t\t\t\t\tbeanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Mapped value [\" + value + \"] for scope key [\" +\n\t\t\t\t\t\t\tscopeKey + \"] is not an instance of required type [\" + Scope.class.getName() +\n\t\t\t\t\t\t\t\"] or a corresponding Class or String value indicating a Scope implementation\");\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n}\n","sourceCodeStart":95,"sourceCodeEnd":122,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java#L95-L122","documentation":"CustomScopeConfigurer.postProcessBeanFactory iterates the scopes map and accepts only Scope instances, Class objects (assignable to Scope), or String class names. Any other type for a scope value throws IllegalArgumentException, because the configurer cannot turn it into a Scope registration.","triggerScenarios":"Registering a custom scope via CustomScopeConfigurer.setScopes with a map value that is neither a Scope, a Class, nor a String - e.g. accidentally putting a bean instance, a Map, or an arbitrary object.","commonSituations":"XML <bean class=\"...CustomScopeConfigurer\"> with a <map> entry whose value ref points at a non-Scope bean; programmatic configurer.getScopes().put(name, wrongObject); copy-paste wiring mistake using a factory or DTO instead of a Scope.","solutions":["Map each scope key to an actual Scope instance (or the Scope implementation Class / its fully-qualified class name String).","If using XML, ensure <entry key=\"...\"><bean class=\"...MyScope\"/></entry> refers to a Scope subtype.","Remove or correct the mis-typed entry."],"exampleFix":"<!-- before -->\n<bean class=\"o.s.b.f.config.CustomScopeConfigurer\">\n  <property name=\"scopes\">\n    <map><entry key=\"tenant\" value=\"com.acme.TenantManager\"/></map>\n  </property>\n</bean>\n<!-- after -->\n<bean class=\"o.s.b.f.config.CustomScopeConfigurer\">\n  <property name=\"scopes\">\n    <map><entry key=\"tenant\"><bean class=\"com.acme.TenantScope\"/></entry></map>\n  </property>\n</bean>","handlingStrategy":"type-guard","validationCode":"for (Map.Entry<String,Object> e : scopes.entrySet()) {\n  Object v = e.getValue();\n  boolean ok = v instanceof Scope || v instanceof Class || v instanceof String;\n  if (!ok) throw new IllegalArgumentException(e.getKey() + \" -> invalid scope value type \" + v.getClass());\n}","typeGuard":"boolean validScopeValue(Object v) {\n  return v instanceof Scope || v instanceof Class || v instanceof String;\n}","tryCatchPattern":null,"preventionTips":["Map scope keys only to Scope instances, Scope Class objects, or Scope FQN Strings.","Double-check XML <entry> values point at Scope beans, not arbitrary beans.","Add a config sanity test validating CustomScopeConfigurer.getScopes() value types."],"tags":["spring","scope","configuration","type-mismatch"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}