Description
pascal gehl opened SPR-12292 and commented
This affects more spring-boot but the root of the problem is in CompositePropertySource.
Spring-boot PropertySourceUtils.getSubProperties is used in RelaxedPropertyResolver.getSubProperties to extract a subset of properties starting with a prefix.
PropertySourceUtils.getSubProperties only works on EnumerablePropertySource as
public static Map<String, Object> getSubProperties(PropertySources propertySources, String rootPrefix, String keyPrefix) {
RelaxedNames keyPrefixes = new RelaxedNames(keyPrefix);
Map<String, Object> subProperties = new LinkedHashMap<String, Object>();
for (PropertySource<?> source : propertySources) {
if (source instanceof EnumerablePropertySource) {
for (String name : ((EnumerablePropertySource<?>) source).getPropertyNames()) {
String key = PropertySourceUtils.getSubKey(name, rootPrefix, keyPrefixes);
if (key != null) {
subProperties.put(key, source.getProperty(name));
}
}
}
}
return Collections.unmodifiableMap(subProperties);
}
Unfortunately that code ignores all @PropertySource
annotated classes because the resulting instances are CompositePropertySource.
This makes it impossible to declare @PropertySource
annotated classes containing prefixed configurations and later on extract all those configuration properties using RelaxedPropertyResolver.getSubProperties.
This issue could be fixed by having CompositePropertySource implement EnumerablePropertySource.
Affects: 4.0.7, 4.1.1
Issue Links:
- CompositePropertySource doesn't fulfil EnumerablePropertySource [SPR-12788] #17385 CompositePropertySource doesn't fulfil EnumerablePropertySource
Referenced from: commits 9d96958