MutablePropertySources constructor
MutablePropertySources()
A mutable container for managing an ordered list of PropertySource objects.
This class allows adding, removing, and retrieving property sources dynamically by name or position. It maintains the search order for property resolution, where the first source added has the highest precedence during lookups.
This container is typically passed to a PropertySourcesPropertyResolver to resolve environment or configuration properties.
Example usage:
final sources = MutablePropertySources();
final defaults = MapPropertySource('defaults', {'debug': 'false'});
final env = MapPropertySource('env', {'debug': 'true'});
sources.addLast(defaults);
sources.addFirst(env); // env now has higher precedence
final value = sources.get('env')?.getProperty('debug'); // 'true'
sources.remove('defaults');
Ordering Methods
You can control precedence using:
This is particularly useful for layered configuration such as: command-line args > environment variables > default config.
Implementation
MutablePropertySources();