Top Description Fields Constructors Methods
org.springframework.core.env

public abstract Class AbstractPropertyResolver

extends Object
implements ConfigurablePropertyResolver
Class Inheritance
All Implemented Interfaces
org.springframework.core.env.ConfigurablePropertyResolver, org.springframework.core.env.PropertyResolver
Known Direct Subclasses
org.springframework.core.env.PropertySourcesPropertyResolver
Imports
java.util.Collections, .LinkedHashSet, .Set, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.convert.ConversionService, org.springframework.core.convert.support.ConfigurableConversionService, .DefaultConversionService, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .PropertyPlaceholderHelper, .SystemPropertyUtils

Abstract base class for resolving properties against any underlying source.
Authors
Chris Beams, Juergen Hoeller
Since
3.1

Field Summary

Modifier and TypeField and Description
private volatile ConfigurableConversionService
private boolean
protected final Log
private PropertyPlaceholderHelper
private String
private String
private final Set<String>
private PropertyPlaceholderHelper
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
containsProperty(String key)

Implements org.springframework.core.env.PropertyResolver.containsProperty.

Return whether the given property key is available for resolution, i.e. if the value for the given key is not null.
protected <T> T

Returns:

the converted value, or the original value if no conversion is necessary
convertValueIfNecessary
(Object
the original property value
value
,
Class<T>
the specified target type for property retrieval
targetType
)

Convert the given value to the specified target type, if necessary.

private PropertyPlaceholderHelper
createPlaceholderHelper(boolean ignoreUnresolvablePlaceholders)

private String
public ConfigurableConversionService
public String
getProperty(String
the property name to resolve
key
)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or null if the key cannot be resolved.
public String
getProperty(String
the property name to resolve
key
,
String
the default value to return if no value is found
defaultValue
)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.
public <T> T
getProperty(String
the property name to resolve
key
,
Class<T>
the expected type of the property value
targetType
,
T
the default value to return if no value is found
defaultValue
)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.
protected abstract String

Returns:

the property value or null if none found
getPropertyAsRawString
(String
the property name to resolve
key
)

Retrieve the specified property as a raw String, i.e. without resolution of nested placeholders.

public String
getRequiredProperty(String key)

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key (never null).
public <T> T
getRequiredProperty(String key, Class<T> valueType)

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key, converted to the given targetType (never null).
protected String
resolveNestedPlaceholders(String value)

Resolve placeholders within the given string, deferring to the value of setIgnoreUnresolvableNestedPlaceholders to determine whether any unresolvable placeholders should raise an exception or be ignored.

public String
resolvePlaceholders(String
the String to resolve
text
)

Implements org.springframework.core.env.PropertyResolver.resolvePlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty.
public String
resolveRequiredPlaceholders(String text)

Implements org.springframework.core.env.PropertyResolver.resolveRequiredPlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty.
public void
public void
setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setIgnoreUnresolvableNestedPlaceholders.

Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property.
public void
setPlaceholderPrefix(String placeholderPrefix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderPrefix.

Set the prefix that placeholders replaced by this resolver must begin with.
public void
setPlaceholderSuffix(String placeholderSuffix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderSuffix.

Set the suffix that placeholders replaced by this resolver must end with.
public void
setRequiredProperties(String... requiredProperties)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setRequiredProperties.

Specify which properties must be present, to be verified by validateRequiredProperties().
public void
setValueSeparator(String valueSeparator)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setValueSeparator.

Specify the separating character between the placeholders replaced by this resolver and their associated default value, or null if no such special character should be processed as a value separator.
public void
validateRequiredProperties()

Implements org.springframework.core.env.ConfigurablePropertyResolver.validateRequiredProperties.

Validate that each of the properties specified by setRequiredProperties is present and resolves to a non-null value.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conversionServiceback to summary
private volatile ConfigurableConversionService conversionService
Annotations
@Nullable
ignoreUnresolvableNestedPlaceholdersback to summary
private boolean ignoreUnresolvableNestedPlaceholders
loggerback to summary
protected final Log logger
nonStrictHelperback to summary
private PropertyPlaceholderHelper nonStrictHelper
Annotations
@Nullable
placeholderPrefixback to summary
private String placeholderPrefix
placeholderSuffixback to summary
private String placeholderSuffix
requiredPropertiesback to summary
private final Set<String> requiredProperties
strictHelperback to summary
private PropertyPlaceholderHelper strictHelper
Annotations
@Nullable
valueSeparatorback to summary
private String valueSeparator
Annotations
@Nullable

Constructor Detail

AbstractPropertyResolverback to summary
public AbstractPropertyResolver()

Method Detail

containsPropertyback to summary
public boolean containsProperty(String key)

Implements org.springframework.core.env.PropertyResolver.containsProperty.

Doc from org.springframework.core.env.PropertyResolver.containsProperty.

Return whether the given property key is available for resolution, i.e. if the value for the given key is not null.

Annotations
@Override
convertValueIfNecessaryback to summary
protected <T> T convertValueIfNecessary(Object value, Class<T> targetType)

Convert the given value to the specified target type, if necessary.

Parameters
value:Object

the original property value

targetType:Class<T>

the specified target type for property retrieval

Returns:T

the converted value, or the original value if no conversion is necessary

Annotations
@SuppressWarnings:unchecked
@Nullable
Since
4.3.5
createPlaceholderHelperback to summary
private PropertyPlaceholderHelper createPlaceholderHelper(boolean ignoreUnresolvablePlaceholders)
doResolvePlaceholdersback to summary
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper)
getConversionServiceback to summary
public ConfigurableConversionService getConversionService()

Implements org.springframework.core.env.ConfigurablePropertyResolver.getConversionService.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.getConversionService.

Return the ConfigurableConversionService 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());
Annotations
@Override
getPropertyback to summary
public String getProperty(String key)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Doc from org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or null if the key cannot be resolved.

Parameters
key:String

the property name to resolve

Annotations
@Override
@Nullable
getPropertyback to summary
public String getProperty(String key, String defaultValue)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Doc from org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

Parameters
key:String

the property name to resolve

defaultValue:String

the default value to return if no value is found

Annotations
@Override
getPropertyback to summary
public <T> T getProperty(String key, Class<T> targetType, T defaultValue)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Doc from org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

Parameters
key:String

the property name to resolve

targetType:Class<T>

the expected type of the property value

defaultValue:T

the default value to return if no value is found

Annotations
@Override
getPropertyAsRawStringback to summary
protected abstract String getPropertyAsRawString(String key)

Retrieve the specified property as a raw String, i.e. without resolution of nested placeholders.

Parameters
key:String

the property name to resolve

Returns:String

the property value or null if none found

Annotations
@Nullable
getRequiredPropertyback to summary
public String getRequiredProperty(String key) throws IllegalStateException

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Doc from org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key (never null).

Annotations
@Override
Exceptions
IllegalStateException:
if the key cannot be resolved
getRequiredPropertyback to summary
public <T> T getRequiredProperty(String key, Class<T> valueType) throws IllegalStateException

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Doc from org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key, converted to the given targetType (never null).

Annotations
@Override
Exceptions
IllegalStateException:
if the given key cannot be resolved
resolveNestedPlaceholdersback to summary
protected String resolveNestedPlaceholders(String value)

Resolve placeholders within the given string, deferring to the value of setIgnoreUnresolvableNestedPlaceholders to determine whether any unresolvable placeholders should raise an exception or be ignored.

Invoked from getProperty and its variants, implicitly resolving nested placeholders. In contrast, resolvePlaceholders and resolveRequiredPlaceholders 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
setIgnoreUnresolvableNestedPlaceholders
resolvePlaceholdersback to summary
public String resolvePlaceholders(String text)

Implements org.springframework.core.env.PropertyResolver.resolvePlaceholders.

Doc from org.springframework.core.env.PropertyResolver.resolvePlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty. Unresolvable placeholders with no default value are ignored and passed through unchanged.

Parameters
text:String

the String to resolve

Returns:String

the resolved String (never null)

Annotations
@Override
resolveRequiredPlaceholdersback to summary
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException

Implements org.springframework.core.env.PropertyResolver.resolveRequiredPlaceholders.

Doc from org.springframework.core.env.PropertyResolver.resolveRequiredPlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty. Unresolvable placeholders with no default value will cause an IllegalArgumentException to be thrown.

Returns:String

the resolved String (never null)

Annotations
@Override
Exceptions
IllegalArgumentException:
if given text is null or if any placeholders are unresolvable
setConversionServiceback to summary
public void setConversionService(ConfigurableConversionService conversionService)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setConversionService.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setConversionService.

Set the ConfigurableConversionService to be used when performing type conversions on properties.

Note

as an alternative to fully replacing the ConversionService, consider adding or removing individual Converter instances by drilling into getConversionService() and calling methods such as #addConverter.

Annotations
@Override
setIgnoreUnresolvableNestedPlaceholdersback to summary
public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setIgnoreUnresolvableNestedPlaceholders.

Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property. A false value indicates strict resolution, i.e. that an exception will be thrown. A true value indicates that unresolvable nested placeholders should be passed through in their unresolved ${...} form.

The default is false.

Annotations
@Override
Since
3.2
setPlaceholderPrefixback to summary
public void setPlaceholderPrefix(String placeholderPrefix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderPrefix.

Set the prefix that placeholders replaced by this resolver must begin with.

The default is "${".

Annotations
@Override
See Also
org.springframework.util.SystemPropertyUtils#PLACEHOLDER_PREFIX
setPlaceholderSuffixback to summary
public void setPlaceholderSuffix(String placeholderSuffix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderSuffix.

Set the suffix that placeholders replaced by this resolver must end with.

The default is "}".

Annotations
@Override
See Also
org.springframework.util.SystemPropertyUtils#PLACEHOLDER_SUFFIX
setRequiredPropertiesback to summary
public void setRequiredProperties(String... requiredProperties)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setRequiredProperties.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setRequiredProperties.

Specify which properties must be present, to be verified by validateRequiredProperties().

Annotations
@Override
setValueSeparatorback to summary
public void setValueSeparator(String valueSeparator)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setValueSeparator.

Specify the separating character between the placeholders replaced by this resolver and their associated default value, or null if no such special character should be processed as a value separator.

The default is ":".

Annotations
@Override
See Also
org.springframework.util.SystemPropertyUtils#VALUE_SEPARATOR
validateRequiredPropertiesback to summary
public void validateRequiredProperties()

Implements org.springframework.core.env.ConfigurablePropertyResolver.validateRequiredProperties.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.validateRequiredProperties.

Validate that each of the properties specified by setRequiredProperties is present and resolves to a non-null value.

Annotations
@Override