commit
5df64afe97
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue