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 Pattern
Regex pattern used for property substitution in the form${property.name[:default]}
. -
Method Summary
Modifier and TypeMethodDescriptiondefault PropertySource
andThen
(PropertySource next) Combines this property source with another, returning the first non-null value found between the two.default boolean
containsProperty
(String name) Checks if a property is defined.Retrieves the value of a property by name.default String
Returns the property value, or the given default if not present.default boolean
getBoolean
(String name) Returns the value of the property as a boolean.default boolean
getBoolean
(String name, boolean defaultValue) Returns the value of the property as a boolean, falling back to a default if not present.static PropertySource
join
(PropertySource... propertySources) Joins multiplePropertySource
instances into a single one.default String
Retrieves the value of a property by name and throws if not present.default String
substituteProperties
(String template) Substitutes all placeholders of the form${property[:default]}
in the given template string.
-
Field Details
-
substitutionPattern
Regex pattern used for property substitution in the form${property.name[:default]}
.
-
-
Method Details
-
get
Retrieves the value of a property by name.- Parameters:
name
- the name of the property to look up- Returns:
- the property value, or
null
if not found
-
getBoolean
Returns the value of the property as a boolean.- Parameters:
name
- the name of the property to look up- Returns:
true
if the value is "true" (case-insensitive),false
otherwise 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
defaultValue
if not present
-
get
Returns the property value, or the given default if not present.- Parameters:
name
- the name of the propertydefaultValue
- the fallback value to use if the property is not set- Returns:
- the property value or the default
-
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:
true
if 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
-
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 multiplePropertySource
instances 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
-