Class AbstractPropertyResolver
- All Implemented Interfaces:
ConfigurablePropertyResolver
,PropertyResolver
- Direct Known Subclasses:
PropertySourcesPropertyResolver
- Since:
- 3.1
- Author:
- Chris Beams, Juergen Hoeller
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsProperty
(String key) Return whether the given property key is available for resolution, i.e.protected <T> T
convertValueIfNecessary
(Object value, Class<T> targetType) Convert the given value to the specified target type, if necessary.Return theConfigurableConversionService
used when performing type conversions on properties.getProperty
(String key) Return the property value associated with the given key, ornull
if the key cannot be resolved.<T> T
getProperty
(String key, Class<T> targetType, T defaultValue) Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.getProperty
(String key, String defaultValue) Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.protected abstract String
Retrieve the specified property as a raw String, i.e.Return the property value associated with the given key (nevernull
).<T> T
getRequiredProperty
(String key, Class<T> valueType) Return the property value associated with the given key, converted to the given targetType (nevernull
).protected String
resolveNestedPlaceholders
(String value) Resolve placeholders within the given string, deferring to the value ofsetIgnoreUnresolvableNestedPlaceholders(boolean)
to determine whether any unresolvable placeholders should raise an exception or be ignored.resolvePlaceholders
(String text) Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String)
.Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String)
.void
setConversionService
(ConfigurableConversionService conversionService) Set theConfigurableConversionService
to be used when performing type conversions on properties.void
setIgnoreUnresolvableNestedPlaceholders
(boolean ignoreUnresolvableNestedPlaceholders) Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property.void
setPlaceholderPrefix
(String placeholderPrefix) Set the prefix that placeholders replaced by this resolver must begin with.void
setPlaceholderSuffix
(String placeholderSuffix) Set the suffix that placeholders replaced by this resolver must end with.void
setRequiredProperties
(String... requiredProperties) Specify which properties must be present, to be verified byConfigurablePropertyResolver.validateRequiredProperties()
.void
setValueSeparator
(String valueSeparator) Specify the separating character between the placeholders replaced by this resolver and their associated default value, ornull
if no such special character should be processed as a value separator.void
Validate that each of the properties specified byConfigurablePropertyResolver.setRequiredProperties(java.lang.String...)
is present and resolves to a non-null
value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.core.env.PropertyResolver
getProperty
-
Field Details
-
logger
-
-
Constructor Details
-
AbstractPropertyResolver
public AbstractPropertyResolver()
-
-
Method Details
-
getConversionService
Description copied from interface:ConfigurablePropertyResolver
Return theConfigurableConversionService
used when performing type conversions on properties.The configurable nature of the returned conversion service allows for the convenient addition and removal of individual
Converter
instances:ConfigurableConversionService cs = env.getConversionService(); cs.addConverter(new FooConverter());
-
setConversionService
Description copied from interface:ConfigurablePropertyResolver
Set theConfigurableConversionService
to be used when performing type conversions on properties.Note: as an alternative to fully replacing the
ConversionService
, consider adding or removing individualConverter
instances by drilling intoConfigurablePropertyResolver.getConversionService()
and calling methods such as#addConverter
. -
setPlaceholderPrefix
Set the prefix that placeholders replaced by this resolver must begin with.The default is "${".
- Specified by:
setPlaceholderPrefix
in interfaceConfigurablePropertyResolver
- See Also:
-
setPlaceholderSuffix
Set the suffix that placeholders replaced by this resolver must end with.The default is "}".
- Specified by:
setPlaceholderSuffix
in interfaceConfigurablePropertyResolver
- See Also:
-
setValueSeparator
Specify the separating character between the placeholders replaced by this resolver and their associated default value, ornull
if no such special character should be processed as a value separator.The default is ":".
- Specified by:
setValueSeparator
in interfaceConfigurablePropertyResolver
- See Also:
-
setIgnoreUnresolvableNestedPlaceholders
public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders) Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property. Afalse
value indicates strict resolution, i.e. that an exception will be thrown. Atrue
value indicates that unresolvable nested placeholders should be passed through in their unresolved ${...} form.The default is
false
.- Specified by:
setIgnoreUnresolvableNestedPlaceholders
in interfaceConfigurablePropertyResolver
- Since:
- 3.2
-
setRequiredProperties
Description copied from interface:ConfigurablePropertyResolver
Specify which properties must be present, to be verified byConfigurablePropertyResolver.validateRequiredProperties()
.- Specified by:
setRequiredProperties
in interfaceConfigurablePropertyResolver
-
validateRequiredProperties
public void validateRequiredProperties()Description copied from interface:ConfigurablePropertyResolver
Validate that each of the properties specified byConfigurablePropertyResolver.setRequiredProperties(java.lang.String...)
is present and resolves to a non-null
value.- Specified by:
validateRequiredProperties
in interfaceConfigurablePropertyResolver
-
containsProperty
Description copied from interface:PropertyResolver
Return whether the given property key is available for resolution, i.e. if the value for the given key is notnull
.- Specified by:
containsProperty
in interfacePropertyResolver
-
getProperty
Description copied from interface:PropertyResolver
Return the property value associated with the given key, ornull
if the key cannot be resolved.- Specified by:
getProperty
in interfacePropertyResolver
- Parameters:
key
- the property name to resolve- See Also:
-
getProperty
Description copied from interface:PropertyResolver
Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.- Specified by:
getProperty
in interfacePropertyResolver
- Parameters:
key
- the property name to resolvedefaultValue
- the default value to return if no value is found- See Also:
-
getProperty
Description copied from interface:PropertyResolver
Return the property value associated with the given key, ordefaultValue
if the key cannot be resolved.- Specified by:
getProperty
in interfacePropertyResolver
- Parameters:
key
- the property name to resolvetargetType
- the expected type of the property valuedefaultValue
- the default value to return if no value is found- See Also:
-
getRequiredProperty
Description copied from interface:PropertyResolver
Return the property value associated with the given key (nevernull
).- Specified by:
getRequiredProperty
in interfacePropertyResolver
- Throws:
IllegalStateException
- if the key cannot be resolved- See Also:
-
getRequiredProperty
Description copied from interface:PropertyResolver
Return the property value associated with the given key, converted to the given targetType (nevernull
).- Specified by:
getRequiredProperty
in interfacePropertyResolver
- Throws:
IllegalStateException
- if the given key cannot be resolved
-
resolvePlaceholders
Description copied from interface:PropertyResolver
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String)
. Unresolvable placeholders with no default value are ignored and passed through unchanged.- Specified by:
resolvePlaceholders
in interfacePropertyResolver
- Parameters:
text
- the String to resolve- Returns:
- the resolved String (never
null
) - See Also:
-
resolveRequiredPlaceholders
Description copied from interface:PropertyResolver
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String)
. Unresolvable placeholders with no default value will cause an IllegalArgumentException to be thrown.- Specified by:
resolveRequiredPlaceholders
in interfacePropertyResolver
- Returns:
- the resolved String (never
null
) - Throws:
IllegalArgumentException
- if given text isnull
or if any placeholders are unresolvable
-
resolveNestedPlaceholders
Resolve placeholders within the given string, deferring to the value ofsetIgnoreUnresolvableNestedPlaceholders(boolean)
to determine whether any unresolvable placeholders should raise an exception or be ignored.Invoked from
getProperty(java.lang.String)
and its variants, implicitly resolving nested placeholders. In contrast,resolvePlaceholders(java.lang.String)
andresolveRequiredPlaceholders(java.lang.String)
do not delegate to this method but rather perform their own handling of unresolvable placeholders, as specified by each of those methods.- Since:
- 3.2
- See Also:
-
convertValueIfNecessary
Convert the given value to the specified target type, if necessary.- Parameters:
value
- the original property valuetargetType
- the specified target type for property retrieval- Returns:
- the converted value, or the original value if no conversion is necessary
- Since:
- 4.3.5
-
getPropertyAsRawString
Retrieve the specified property as a raw String, i.e. without resolution of nested placeholders.- Parameters:
key
- the property name to resolve- Returns:
- the property value or
null
if none found
-