Package org.springframework.core.env

# Class AbstractPropertyResolver

java.lang.Object
org.springframework.core.env.AbstractPropertyResolver

All Implemented Interfaces:
  `ConfigurablePropertyResolver`, `PropertyResolver`

Direct Known Subclasses:
  `PropertySourcesPropertyResolver`

public abstract class AbstractPropertyResolver extends Object implements ConfigurablePropertyResolver
Abstract base class for resolving properties against any underlying source.

Since:
  3.1
Author:
  Chris Beams, Juergen Hoeller, Sam Brannen

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`DEFAULT_PLACEHOLDER_ESCAPE_CHARACTER_PROPERTY_NAME`
JVM system property used to change the default escape character for property placeholder support: "spring.placeholder.escapeCharacter.default".
`protected final org.apache.commons.logging.Log`
`logger`

## Constructor Summary

Constructors
Constructor
Description
`AbstractPropertyResolver()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`containsProperty(String key)`
Determine whether the given property key is available for resolution — for example, if the value for the given key is not `null`.
`protected <T> T`
`convertValueIfNecessary(Object value, Class<T> targetType)`
Convert the given value to the specified target type, if necessary.
`ConfigurableConversionService`
`getConversionService()`
Return the `ConfigurableConversionService` used when performing type conversions on properties.
`static Character`
`getDefaultEscapeCharacter()`
Get the default escape character to use when parsing strings for property placeholder resolution.
`String`
`getProperty(String key)`
Resolve the property value associated with the given key, or `null` if the key cannot be resolved.
`<T> T`
`getProperty(String key, Class<T> targetType, T defaultValue)`
Resolve the property value associated with the given key, or `defaultValue` if the key cannot be resolved.
`String`
`getProperty(String key, String defaultValue)`
Resolve the property value associated with the given key, or `defaultValue` if the key cannot be resolved.
`protected abstract String`
`getPropertyAsRawString(String key)`
Retrieve the specified property as a raw String, i.e.
`String`
`getRequiredProperty(String key)`
Resolve the property value associated with the given key (never `null`).
`<T> T`
`getRequiredProperty(String key, Class<T> valueType)`
Resolve 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(boolean)` to determine whether any unresolvable placeholders should raise an exception or be ignored.
`String`
`resolvePlaceholders(String text)`
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by `PropertyResolver.getProperty(java.lang.String)`.
`String`
`resolveRequiredPlaceholders(String text)`
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by `PropertyResolver.getProperty(java.lang.String)`.
`void`
`setConversionService(ConfigurableConversionService conversionService)`
Set the `ConfigurableConversionService` to be used when performing type conversions on properties.
`void`
`setEscapeCharacter(Character escapeCharacter)`
Set the escape character to use to ignore the placeholder prefix and the value separator, or `null` if no escaping should take place.
`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 by `ConfigurablePropertyResolver.validateRequiredProperties()`.
`void`
`setValueSeparator(String valueSeparator)`
Set the separating character to be honored between placeholders replaced by this resolver and their associated default values, or `null` if no such special character should be processed as a value separator.
`void`
`validateRequiredProperties()`
Validate that each of the properties specified by `ConfigurablePropertyResolver.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

### DEFAULT_PLACEHOLDER_ESCAPE_CHARACTER_PROPERTY_NAME

public static final String DEFAULT_PLACEHOLDER_ESCAPE_CHARACTER_PROPERTY_NAME
JVM 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.properties` file in the root of the classpath.

Since:
  6.2.7
See Also:
  - `getDefaultEscapeCharacter()`
  - Constant Field Values

### logger

protected final org.apache.commons.logging.Log logger

## Constructor Details

### AbstractPropertyResolver

public AbstractPropertyResolver()

## Method Details

### getConversionService

public ConfigurableConversionService getConversionService()
Description copied from interface: `ConfigurablePropertyResolver`
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());

Specified by:
  `getConversionService` in interface `ConfigurablePropertyResolver`
See Also:
  - `PropertyResolver.getProperty(String, Class)`
  - `ConverterRegistry.addConverter(org.springframework.core.convert.converter.Converter<?, ?>)`

### setConversionService

public void setConversionService(ConfigurableConversionService conversionService)
Description copied from interface: `ConfigurablePropertyResolver`
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 `ConfigurablePropertyResolver.getConversionService()` and calling methods such as `#addConverter`.

Specified by:
  `setConversionService` in interface `ConfigurablePropertyResolver`
See Also:
  - `PropertyResolver.getProperty(String, Class)`
  - `ConfigurablePropertyResolver.getConversionService()`
  - `ConverterRegistry.addConverter(org.springframework.core.convert.converter.Converter<?, ?>)`

### setPlaceholderPrefix

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

The default is `"${"`.

Specified by:
  `setPlaceholderPrefix` in interface `ConfigurablePropertyResolver`
See Also:
  - `SystemPropertyUtils.PLACEHOLDER_PREFIX`

### setPlaceholderSuffix

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

The default is `"}"`.

Specified by:
  `setPlaceholderSuffix` in interface `ConfigurablePropertyResolver`
See Also:
  - `SystemPropertyUtils.PLACEHOLDER_SUFFIX`

### setValueSeparator

public void setValueSeparator(@Nullable String valueSeparator)
Set the separating character to be honored between placeholders replaced by this resolver and their associated default values, or `null` if no such special character should be processed as a value separator.

The default is `":"`.

Specified by:
  `setValueSeparator` in interface `ConfigurablePropertyResolver`
See Also:
  - `SystemPropertyUtils.VALUE_SEPARATOR`

### setEscapeCharacter

public void setEscapeCharacter(@Nullable Character escapeCharacter)
Set the escape character to use to ignore the placeholder prefix and the value separator, or `null` if no escaping should take place.

The default is determined by `getDefaultEscapeCharacter()`.

Specified by:
  `setEscapeCharacter` in interface `ConfigurablePropertyResolver`
Since:
  6.2

### 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. 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`.

Specified by:
  `setIgnoreUnresolvableNestedPlaceholders` in interface `ConfigurablePropertyResolver`
Since:
  3.2

### setRequiredProperties

public void setRequiredProperties(String... requiredProperties)
Description copied from interface: `ConfigurablePropertyResolver`
Specify which properties must be present, to be verified by `ConfigurablePropertyResolver.validateRequiredProperties()`.

Specified by:
  `setRequiredProperties` in interface `ConfigurablePropertyResolver`

### validateRequiredProperties

public void validateRequiredProperties()
Description copied from interface: `ConfigurablePropertyResolver`
Validate that each of the properties specified by `ConfigurablePropertyResolver.setRequiredProperties(java.lang.String...)` is present and resolves to a non-`null` value.

Specified by:
  `validateRequiredProperties` in interface `ConfigurablePropertyResolver`

### containsProperty

public boolean containsProperty(String key)
Description copied from interface: `PropertyResolver`
Determine whether the given property key is available for resolution — for example, if the value for the given key is not `null`.

Specified by:
  `containsProperty` in interface `PropertyResolver`

### getProperty

@Nullable public String getProperty(String key)
Description copied from interface: `PropertyResolver`
Resolve the property value associated with the given key, or `null` if the key cannot be resolved.

Specified by:
  `getProperty` in interface `PropertyResolver`
Parameters:
  `key` - the property name to resolve
See Also:
  - `PropertyResolver.getProperty(String, String)`
  - `PropertyResolver.getProperty(String, Class)`
  - `PropertyResolver.getRequiredProperty(String)`

### getProperty

public String getProperty(String key, String defaultValue)
Description copied from interface: `PropertyResolver`
Resolve the property value associated with the given key, or `defaultValue` if the key cannot be resolved.

Specified by:
  `getProperty` in interface `PropertyResolver`
Parameters:
  `key` - the property name to resolve
  `defaultValue` - the default value to return if no value is found
See Also:
  - `PropertyResolver.getRequiredProperty(String)`
  - `PropertyResolver.getProperty(String, Class)`

### getProperty

public <T> T getProperty(String key, Class<T> targetType, T defaultValue)
Description copied from interface: `PropertyResolver`
Resolve the property value associated with the given key, or `defaultValue` if the key cannot be resolved.

Specified by:
  `getProperty` in 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:
  - `PropertyResolver.getRequiredProperty(String, Class)`

### getRequiredProperty

public String getRequiredProperty(String key) throws IllegalStateException
Description copied from interface: `PropertyResolver`
Resolve the property value associated with the given key (never `null`).

Specified by:
  `getRequiredProperty` in interface `PropertyResolver`
Throws:
  `IllegalStateException` - if the key cannot be resolved
See Also:
  - `PropertyResolver.getRequiredProperty(String, Class)`

### getRequiredProperty

public <T> T getRequiredProperty(String key, Class<T> valueType) throws IllegalStateException
Description copied from interface: `PropertyResolver`
Resolve the property value associated with the given key, converted to the given targetType (never `null`).

Specified by:
  `getRequiredProperty` in interface `PropertyResolver`
Throws:
  `IllegalStateException` - if the given key cannot be resolved

### resolvePlaceholders

public String resolvePlaceholders(String text)
Description copied from interface: `PropertyResolver`
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by `PropertyResolver.getProperty(java.lang.String)`. Unresolvable placeholders with no default value are ignored and passed through unchanged.

Specified by:
  `resolvePlaceholders` in interface `PropertyResolver`
Parameters:
  `text` - the String to resolve
Returns:
  the resolved String (never `null`)
See Also:
  - `PropertyResolver.resolveRequiredPlaceholders(java.lang.String)`

### resolveRequiredPlaceholders

public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException
Description copied from interface: `PropertyResolver`
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by `PropertyResolver.getProperty(java.lang.String)`. Unresolvable placeholders with no default value will cause an IllegalArgumentException to be thrown.

Specified by:
  `resolveRequiredPlaceholders` in interface `PropertyResolver`
Returns:
  the resolved String (never `null`)
Throws:
  `IllegalArgumentException` - if given text is `null` or if any placeholders are unresolvable

### resolveNestedPlaceholders

protected String resolveNestedPlaceholders(String value)
Resolve placeholders within the given string, deferring to the value of `setIgnoreUnresolvableNestedPlaceholders(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)` and `resolveRequiredPlaceholders(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:
  - `setIgnoreUnresolvableNestedPlaceholders(boolean)`

### convertValueIfNecessary

@Nullable protected <T> T convertValueIfNecessary(Object value, @Nullable Class<T> targetType)
Convert 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

@Nullable protected abstract String getPropertyAsRawString(String key)
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

### getDefaultEscapeCharacter

@Nullable public static Character getDefaultEscapeCharacter() throws IllegalArgumentException
Get 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, `null` if 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_VALUE` or a string containing more than one character
Since:
  6.2.7
See Also:
  - `DEFAULT_PLACEHOLDER_ESCAPE_CHARACTER_PROPERTY_NAME`
  - `SystemPropertyUtils.ESCAPE_CHARACTER`
  - `SpringProperties`