Class AbstractPropertyResolver
- All Implemented Interfaces:
- ConfigurablePropertyResolver,- PropertyResolver
- Direct Known Subclasses:
- PropertySourcesPropertyResolver
- Since:
- 3.1
- Author:
- Chris Beams, Juergen Hoeller, Sam Brannen
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringJVM system property used to change the default escape character for property placeholder support: "spring.placeholder.escapeCharacter.default".protected final org.apache.commons.logging.Log
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleancontainsProperty(String key) Determine whether the given property key is available for resolution — for example, if the value for the given key is notnull.protected <T> @Nullable TconvertValueIfNecessary(Object value, @Nullable Class<T> targetType) Convert the given value to the specified target type, if necessary.Return theConfigurableConversionServiceused when performing type conversions on properties.Get the default escape character to use when parsing strings for property placeholder resolution.getProperty(String key) Resolve the property value associated with the given key, ornullif the key cannot be resolved.<T> TgetProperty(String key, Class<T> targetType, T defaultValue) Resolve the property value associated with the given key, ordefaultValueif the key cannot be resolved.getProperty(String key, String defaultValue) Resolve the property value associated with the given key, ordefaultValueif the key cannot be resolved.Retrieve the specified property as a raw String, i.e.Resolve the property value associated with the given key (nevernull).<T> TgetRequiredProperty(String key, Class<T> valueType) Resolve the property value associated with the given key, converted to the given targetType (nevernull).protected StringresolveNestedPlaceholders(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).voidsetConversionService(ConfigurableConversionService conversionService) Set theConfigurableConversionServiceto be used when performing type conversions on properties.voidsetEscapeCharacter(@Nullable Character escapeCharacter) Set the escape character to use to ignore the placeholder prefix and the value separator, ornullif no escaping should take place.voidsetIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders) Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property.voidsetPlaceholderPrefix(String placeholderPrefix) Set the prefix that placeholders replaced by this resolver must begin with.voidsetPlaceholderSuffix(String placeholderSuffix) Set the suffix that placeholders replaced by this resolver must end with.voidsetRequiredProperties(String... requiredProperties) Specify which properties must be present, to be verified byConfigurablePropertyResolver.validateRequiredProperties().voidsetValueSeparator(@Nullable String valueSeparator) Set the separating character to be honored between placeholders replaced by this resolver and their associated default values, ornullif no such special character should be processed as a value separator.voidValidate that each of the properties specified byConfigurablePropertyResolver.setRequiredProperties(java.lang.String...)is present and resolves to a non-nullvalue.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.env.PropertyResolvergetProperty
- 
Field Details- 
DEFAULT_PLACEHOLDER_ESCAPE_CHARACTER_PROPERTY_NAMEJVM system property used to change the default escape character for property placeholder support: "spring.placeholder.escapeCharacter.default".To configure a custom escape character, supply a string containing a single character (other than Character.MIN_VALUE). For example, supplying the following JVM system property via the command line sets the default escape character to'@'.-Dspring.placeholder.escapeCharacter.default=@ To disable escape character support, set the value to an empty string — for example, by supplying the following JVM system property via the command line. -Dspring.placeholder.escapeCharacter.default= If the property is not set, '\'will be used as the default escape character.May alternatively be configured via a spring.propertiesfile in the root of the classpath.- Since:
- 6.2.7
- See Also:
 
- 
loggerprotected final org.apache.commons.logging.Log logger
 
- 
- 
Constructor Details- 
AbstractPropertyResolverpublic AbstractPropertyResolver()
 
- 
- 
Method Details- 
getConversionServiceDescription copied from interface:ConfigurablePropertyResolverReturn theConfigurableConversionServiceused when performing type conversions on properties.The configurable nature of the returned conversion service allows for the convenient addition and removal of individual Converterinstances:ConfigurableConversionService cs = env.getConversionService(); cs.addConverter(new FooConverter()); - Specified by:
- getConversionServicein interface- ConfigurablePropertyResolver
- See Also:
 
- 
setConversionServiceDescription copied from interface:ConfigurablePropertyResolverSet theConfigurableConversionServiceto be used when performing type conversions on properties.Note: as an alternative to fully replacing the ConversionService, consider adding or removing individualConverterinstances by drilling intoConfigurablePropertyResolver.getConversionService()and calling methods such as#addConverter.- Specified by:
- setConversionServicein interface- ConfigurablePropertyResolver
- See Also:
 
- 
setPlaceholderPrefixSet the prefix that placeholders replaced by this resolver must begin with.The default is "${".- Specified by:
- setPlaceholderPrefixin interface- ConfigurablePropertyResolver
- See Also:
 
- 
setPlaceholderSuffixSet the suffix that placeholders replaced by this resolver must end with.The default is "}".- Specified by:
- setPlaceholderSuffixin interface- ConfigurablePropertyResolver
- See Also:
 
- 
setValueSeparatorSet the separating character to be honored between placeholders replaced by this resolver and their associated default values, ornullif no such special character should be processed as a value separator.The default is ":".- Specified by:
- setValueSeparatorin interface- ConfigurablePropertyResolver
- See Also:
 
- 
setEscapeCharacterSet the escape character to use to ignore the placeholder prefix and the value separator, ornullif no escaping should take place.The default is determined by getDefaultEscapeCharacter().- Specified by:
- setEscapeCharacterin interface- ConfigurablePropertyResolver
- Since:
- 6.2
 
- 
setIgnoreUnresolvableNestedPlaceholderspublic void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders) Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property. Afalsevalue indicates strict resolution, i.e. that an exception will be thrown. Atruevalue indicates that unresolvable nested placeholders should be passed through in their unresolved ${...} form.The default is false.- Specified by:
- setIgnoreUnresolvableNestedPlaceholdersin interface- ConfigurablePropertyResolver
- Since:
- 3.2
 
- 
setRequiredPropertiesDescription copied from interface:ConfigurablePropertyResolverSpecify which properties must be present, to be verified byConfigurablePropertyResolver.validateRequiredProperties().- Specified by:
- setRequiredPropertiesin interface- ConfigurablePropertyResolver
 
- 
validateRequiredPropertiespublic void validateRequiredProperties()Description copied from interface:ConfigurablePropertyResolverValidate that each of the properties specified byConfigurablePropertyResolver.setRequiredProperties(java.lang.String...)is present and resolves to a non-nullvalue.- Specified by:
- validateRequiredPropertiesin interface- ConfigurablePropertyResolver
 
- 
containsPropertyDescription copied from interface:PropertyResolverDetermine whether the given property key is available for resolution — for example, if the value for the given key is notnull.- Specified by:
- containsPropertyin interface- PropertyResolver
 
- 
getPropertyDescription copied from interface:PropertyResolverResolve the property value associated with the given key, ornullif the key cannot be resolved.- Specified by:
- getPropertyin interface- PropertyResolver
- Parameters:
- key- the property name to resolve
- See Also:
 
- 
getPropertyDescription copied from interface:PropertyResolverResolve the property value associated with the given key, ordefaultValueif the key cannot be resolved.- Specified by:
- getPropertyin interface- PropertyResolver
- Parameters:
- key- the property name to resolve
- defaultValue- the default value to return if no value is found
- See Also:
 
- 
getPropertyDescription copied from interface:PropertyResolverResolve the property value associated with the given key, ordefaultValueif the key cannot be resolved.- Specified by:
- getPropertyin interface- PropertyResolver
- Parameters:
- key- the property name to resolve
- targetType- the expected type of the property value
- defaultValue- the default value to return if no value is found
- See Also:
 
- 
getRequiredPropertyDescription copied from interface:PropertyResolverResolve the property value associated with the given key (nevernull).- Specified by:
- getRequiredPropertyin interface- PropertyResolver
- Throws:
- IllegalStateException- if the key cannot be resolved
- See Also:
 
- 
getRequiredPropertyDescription copied from interface:PropertyResolverResolve the property value associated with the given key, converted to the given targetType (nevernull).- Specified by:
- getRequiredPropertyin interface- PropertyResolver
- Throws:
- IllegalStateException- if the given key cannot be resolved
 
- 
resolvePlaceholdersDescription copied from interface:PropertyResolverResolve ${...} 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:
- resolvePlaceholdersin interface- PropertyResolver
- Parameters:
- text- the String to resolve
- Returns:
- the resolved String (never null)
- See Also:
 
- 
resolveRequiredPlaceholdersDescription copied from interface:PropertyResolverResolve ${...} 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:
- resolveRequiredPlaceholdersin interface- PropertyResolver
- Returns:
- the resolved String (never null)
- Throws:
- IllegalArgumentException- if given text is- nullor if any placeholders are unresolvable
 
- 
resolveNestedPlaceholdersResolve 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:
 
- 
convertValueIfNecessaryConvert the given value to the specified target type, if necessary.- Parameters:
- value- the original property value
- targetType- 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
- 
getDefaultEscapeCharacterGet the default escape character to use when parsing strings for property placeholder resolution.This method attempts to retrieve the default escape character configured via the "spring.placeholder.escapeCharacter.default" JVM system property or Spring property. Falls back to '\'if the property has not been set.- Returns:
- the configured default escape character, nullif escape character support has been disabled, or'\'if the property has not been set
- Throws:
- IllegalArgumentException- if the property is configured with an invalid value, such as- Character.MIN_VALUEor a string containing more than one character
- Since:
- 6.2.7
- See Also:
 
 
-