Interface PropertySource
- All Known Implementing Classes:
ApplicationEnvironmentPropertiesSource, ApplicationPropertiesSource, DecryptingPropertySource, DefaultPropertySource, EnvironmentVariablesSource, JavaPropertiesSource, NoOpPropertySource, SimplePropertySource, SpringPropertySource, SystemPropertiesSource
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents a source of configuration properties.
This interface provides a unified way to access application-level configuration values. You can use it to retrieve string, boolean, or substituted values and chain multiple sources together.
Implementations may load properties from system environment variables, property files, Spring contexts, application
Entities, etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternRegex pattern used for property substitution in the form${property.name[:default]}. -
Method Summary
Modifier and TypeMethodDescriptiondefault PropertySourceandThen(PropertySource next) Combines this property source with another, returning the first non-null value found between the two.default booleancontainsProperty(String name) Checks if a property is defined.Retrieves the value of a property by name.default StringReturns the property value, or the given default if not present.default booleangetBoolean(String name) Returns the value of the property as a boolean.default booleangetBoolean(String name, boolean defaultValue) Returns the value of the property as a boolean, falling back to a default if not present.static PropertySourcejoin(PropertySource... propertySources) Joins multiplePropertySourceinstances into a single one.default StringRetrieves the value of a property by name and throws if not present.default StringsubstituteProperties(String template) Substitutes all placeholders of the form${property[:default]}in the given template string.default PropertiessubstituteProperties(Properties properties) Substitutes all placeholders of the form${property[:default]}in the values of the givenPropertiesobject.
-
Field Details
-
substitutionPattern
Regex pattern used for property substitution in the form${property.name[:default]}.
-
-
Method Details
-
get
-
getBoolean
Returns the value of the property as a boolean.- Parameters:
name- the name of the property to look up- Returns:
trueif the value is "true" (case-insensitive),falseotherwise or if not present
-
getBoolean
Returns the value of the property as a boolean, falling back to a default if not present.- Parameters:
name- the name of the propertydefaultValue- the value to return if the property is not set- Returns:
- the parsed boolean value, or
defaultValueif not present
-
get
-
require
Retrieves the value of a property by name and throws if not present.- Parameters:
name- the name of the property- Returns:
- the property value
- Throws:
IllegalStateException- if the property is not found
-
containsProperty
Checks if a property is defined.- Parameters:
name- the name of the property- Returns:
trueif the property is set, otherwisefalse
-
substituteProperties
Substitutes all placeholders of the form${property[:default]}in the given template string.Supports recursive substitutions and default fallback values (e.g.
${env:dev}).- Parameters:
template- the template containing substitutions- Returns:
- the fully substituted string
-
substituteProperties
Substitutes all placeholders of the form${property[:default]}in the values of the givenPropertiesobject.Supports recursive substitutions and default fallback values (e.g.
${env:dev}).- Parameters:
properties- the properties object to substitute values in- Returns:
- a new
Propertiesinstance with all substitutions applied
-
andThen
Combines this property source with another, returning the first non-null value found between the two.If a property is not present in this source, it will delegate to the next.
- Parameters:
next- the fallback property source- Returns:
- a chained property source
-
join
Joins multiplePropertySourceinstances into a single one.The returned property source will resolve properties using the order of the given sources.
- Parameters:
propertySources- the sources to join- Returns:
- a combined
PropertySource
-