Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property placeholders aren't resolved when configuration property binding creates a Map from a property value using a converter #39507

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> targe
ConfigurationProperty property = source.getConfigurationProperty(name);
if (property != null && !hasDescendants) {
getContext().setConfigurationProperty(property);
return getContext().getConverter().convert(property.getValue(), target);
Object result = property.getValue();
result = getContext().getPlaceholdersResolver().resolvePlaceholders(result);
result = getContext().getConverter().convert(result, target);
return result;
}
source = source.filter(name::isAncestorOf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,19 @@ void bindToMapWithWildcardShouldConvertToTheRightType() {
.containsExactly("127.0.0.1", "127.0.0.2");
}

@Test
void bindToMapWithPlaceholdersShouldResolve() {
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new MapConverter());
StandardEnvironment environment = new StandardEnvironment();
Binder binder = new Binder(this.sources, new PropertySourcesPlaceholdersResolver(environment), conversionService, null, null);
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "bar=bc");
this.sources.add(new MockConfigurationPropertySource("foo", "a${bar},${bar}d"));
Map<String, String> map = binder.bind("foo", STRING_STRING_MAP).get();
assertThat(map).containsKey("abc");
assertThat(map).containsKey("bcd");
}

private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) {
ResolvableType keyType = ResolvableType.forClass(keyGeneric);
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));
Expand Down