Skip to content

Commit 5df64af

Browse files
Merge branch '3.1.x' into 3.2.x
Closes gh-39515
2 parents eb75bb1 + 09eb6a7 commit 5df64af

File tree

2 files changed

+19
-3
lines changed
  • spring-boot-project/spring-boot/src

2 files changed

+19
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,7 +62,9 @@ protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> targe
6262
ConfigurationProperty property = source.getConfigurationProperty(name);
6363
if (property != null && !hasDescendants) {
6464
getContext().setConfigurationProperty(property);
65-
return getContext().getConverter().convert(property.getValue(), target);
65+
Object result = property.getValue();
66+
result = getContext().getPlaceholdersResolver().resolvePlaceholders(result);
67+
return getContext().getConverter().convert(result, target);
6668
}
6769
source = source.filter(name::isAncestorOf);
6870
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -610,6 +610,20 @@ void bindToMapWithWildcardShouldConvertToTheRightType() {
610610
.containsExactly("127.0.0.1", "127.0.0.2");
611611
}
612612

613+
@Test
614+
void bindToMapWithPlaceholdersShouldResolve() {
615+
DefaultConversionService conversionService = new DefaultConversionService();
616+
conversionService.addConverter(new MapConverter());
617+
StandardEnvironment environment = new StandardEnvironment();
618+
Binder binder = new Binder(this.sources, new PropertySourcesPlaceholdersResolver(environment),
619+
conversionService, null, null);
620+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "bar=bc");
621+
this.sources.add(new MockConfigurationPropertySource("foo", "a${bar},${bar}d"));
622+
Map<String, String> map = binder.bind("foo", STRING_STRING_MAP).get();
623+
assertThat(map).containsKey("abc");
624+
assertThat(map).containsKey("bcd");
625+
}
626+
613627
private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) {
614628
ResolvableType keyType = ResolvableType.forClass(keyGeneric);
615629
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));

0 commit comments

Comments
 (0)