{"id":"d488ba36a53a9a7f","repo":"spring-projects/spring-framework","slug":"no-stringvalueresolver-specified-pass-a-resolver","errorCode":null,"errorMessage":"No StringValueResolver specified - pass a resolver object into the constructor or override the 'resolveStringValue' method","messagePattern":"No StringValueResolver specified - pass a resolver object into the constructor or override the 'resolveStringValue' method","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java","lineNumber":288,"sourceCode":"\t\t\tObject val = entry.getValue();\n\t\t\tObject newVal = resolveValue(val);\n\t\t\tnewContent.put(newKey, newVal);\n\t\t\tentriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash);\n\t\t}\n\t\tif (entriesModified) {\n\t\t\tmapVal.clear();\n\t\t\tmapVal.putAll(newContent);\n\t\t}\n\t}\n\n\t/**\n\t * Resolve the given String value, for example parsing placeholders.\n\t * @param strVal the original String value\n\t * @return the resolved String value\n\t */\n\tprotected @Nullable String resolveStringValue(String strVal) {\n\t\tif (this.valueResolver == null) {\n\t\t\tthrow new IllegalStateException(\"No StringValueResolver specified - pass a resolver \" +\n\t\t\t\t\t\"object into the constructor or override the 'resolveStringValue' method\");\n\t\t}\n\t\tString resolvedValue = this.valueResolver.resolveStringValue(strVal);\n\t\t// Return original String if not modified.\n\t\treturn (strVal.equals(resolvedValue) ? strVal : resolvedValue);\n\t}\n\n}\n","sourceCodeStart":270,"sourceCodeEnd":297,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java#L270-L297","documentation":"BeanDefinitionVisitor.resolveStringValue delegates placeholder resolution to a StringValueResolver supplied at construction. If no resolver was provided (the field is null) and the subclass did not override resolveStringValue, visiting a bean definition that contains String values (placeholders like ${...}) fails immediately with this IllegalStateException.","triggerScenarios":"Constructing a BeanDefinitionVisitor without a StringValueResolver and then visiting values that need resolving; or a subclass that calls super.resolveStringValue without supplying a resolver.","commonSituations":"Programmatic use of BeanDefinitionVisitor (e.g. PropertyPlaceholderConfigurer-like processing) without passing PropertyResolver.strValResolver; misusing the visitor standalone instead of through PropertySourcesPlaceholderConfigurer; custom visitor subclass forgetting to inject a resolver.","solutions":["Pass a StringValueResolver (e.g. from environment::resolveRequiredPlaceholders) into the BeanDefinitionVisitor constructor.","Override resolveStringValue in your subclass to implement resolution directly.","Prefer PropertySourcesPlaceholderConfigurer / ConfigurableEnvironment.resolvePlaceholders for normal placeholder resolution instead of using the visitor directly."],"exampleFix":"// before\nBeanDefinitionVisitor visitor = new BeanDefinitionVisitor(null);\nvisitor.visitBeanDefinition(beanDef);\n// after\nStringValueResolver r = str -> env.resolveRequiredPlaceholders(str);\nBeanDefinitionVisitor visitor = new BeanDefinitionVisitor(r);\nvisitor.visitBeanDefinition(beanDef);","handlingStrategy":"validation","validationCode":"if (visitorResolver == null && placeholderPresent(beanDefinition)) {\n  throw new IllegalStateException(\"BeanDefinitionVisitor needs a StringValueResolver to resolve placeholders\");\n}","typeGuard":"boolean resolverAvailable(@Nullable StringValueResolver r) {\n  return r != null;\n}","tryCatchPattern":null,"preventionTips":["Always pass a StringValueResolver to BeanDefinitionVisitor, or override resolveStringValue.","Prefer PropertySourcesPlaceholderConfigurer / environment.resolvePlaceholders for placeholder resolution.","Add a constructor assertion that the resolver is non-null when placeholders are expected."],"tags":["spring","placeholder","bean-definition","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}