Merge branch '3.1.x' into 3.2.x

Closes gh-39515
This commit is contained in:
Scott Frederick 2024-02-11 15:09:35 -06:00
commit 5df64afe97
2 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -62,7 +62,9 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
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);
return getContext().getConverter().convert(result, target);
}
source = source.filter(name::isAncestorOf);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -610,6 +610,20 @@ class MapBinderTests {
.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));