PropertyResolver and PropertySource¶
PropertyResolver and PropertySource are components within the Spring Framework used for managing and resolving configuration properties. PropertySource acts as a repository for property key-value pairs, while PropertyResolver provides the interface for accessing and resolving these values, including support for placeholders and type conversion^[600-developer__spring__spring-spel.md].
PropertySource¶
A PropertySource represents a named source of property values, such as environment variables, system properties, or a properties file^[600-developer__spring__spring-spel.md]. It serves as a base abstraction that allows different property origins to be treated uniformly within the Spring environment. This mechanism enables the layering of configuration sources, where properties defined in one source may override those in another^[600-developer__spring__spring-spel.md].
PropertyResolver¶
The PropertyResolver interface is responsible for resolving property values against the underlying property sources^[600-developer__spring__spring-spel.md]. It typically provides functionality to:
- Retrieve the value of a given property.
- Resolve placeholders (e.g.,
${property.name}) within strings. - Perform type conversion, such as converting a string value to an Integer or Boolean^[600-developer__spring__spring-spel.md].
- Handle required properties versus optional properties with default values^[600-developer__spring__spring-spel.md].
Integration and Usage¶
In a typical Spring configuration, PropertySource implementations are aggregated, and a PropertyResolver (often implemented by or wrapped within Environment) is used to access them^[600-developer__spring__spring-spel.md].
For example, PropertySourcesPlaceholderConfigurer is a utility that integrates these concepts to replace ${...} placeholders in bean definitions with values from registered property sources^[600-developer__spring__spring-spel.md].
Related Concepts¶
- [[Spring-SpEL]]
- [[Spring-@Value]]
Sources¶
600-developer__spring__spring-spel.md