Skip to content

CompositePropertySource should extend EnumerablePropertySource [SPR-12292] #16897

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 9d96958

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions