AbstractPropertyResolver class abstract
The common part of property resolvers: placeholder resolution, conversion, defaults and required keys. A subclass only says where raw values come from, in getRawProperty.
Applications practically never extend it; the environment's resolver (PropertySourcesPropertyResolver) covers property sources. It is for a resolver over some other store that should behave like the environment, placeholders and conversion included.
// Placeholders and typed reads over a plain map.
class MapResolver extends AbstractPropertyResolver {
MapResolver(this.values);
final Map<String, String> values;
@override
Object? getRawProperty(String key) => values[key];
}
Spring (Java):
class MapResolver extends AbstractPropertyResolver {
private final Map<String, String> values;
MapResolver(Map<String, String> values) { this.values = values; }
@Override
protected String getPropertyAsRawString(String key) {
return values.get(key);
}
@Override
public <T> T getProperty(String key, Class<T> type) {
String value = values.get(key);
return value == null ? null
: convertValueIfNecessary(resolveNestedPlaceholders(value), type);
}
}
- Implemented types
Constructors
Properties
- conversionService ↔ ConversionService
-
The service that converts values in PropertyResolver.getPropertyAs
and in
@ConfigurationPropertiesbinding.getter/setter pairoverride - escapeCharacter ← String?
-
The character that makes a placeholder prefix or separator literal
(
\${is the text${);\unless changed.nullturns escaping off.no getteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
- ignoreUnresolvableNestedPlaceholders ← bool
-
Whether reading a property whose value contains an unresolvable
placeholder keeps the placeholder as text (
true) instead of throwing (false, the default).no getteroverride - placeholderPrefix ← String
-
The text that opens a placeholder;
${unless changed.no getteroverride - placeholderSuffix ← String
-
The text that closes a placeholder;
}unless changed.no getteroverride - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- valueSeparator ← String?
-
The text between a key and its default in
${key:default};:unless changed.nullturns defaults off, so the whole text is the key.no getteroverride
Methods
-
containsProperty(
String key) → bool -
Whether some source has the property
key, even with an empty value. Use it to tell "set to empty" from "not set".override -
getProperty(
String key, {String? defaultValue}) → String? -
The value of the property
keyas text, placeholders resolved, ordefaultValue(nullunless given) when no source has it.override -
getPropertyAs<
T> (String key, {T? defaultValue}) → T? -
The value of the property
keyconverted toT, ordefaultValuewhen no source has it.override -
getRawProperty(
String key) → Object? -
The stored value of
keyas it is, ornullwhen there is none. -
getRequiredProperty(
String key) → String -
The value of the property
keyas text, for settings the application cannot run without. ThrowsMissingPropertyExceptionwhen no source has it.override -
getRequiredPropertyAs<
T> (String key) → T -
The value of the property
keyconverted toT. ThrowsMissingPropertyExceptionwhen no source has it (or it converts tonull), and aConversionExceptionwhen it cannot be converted.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolvePlaceholders(
String text) → String -
Replaces every
${key}and${key:default}intextwith the property's value, for text written by someone else, such as a message template. A placeholder that cannot be resolved and has no default stays as it is.override -
resolveRequiredPlaceholders(
String text) → String -
Replaces every
${key}and${key:default}intextlike resolvePlaceholders, but throwsPlaceholderResolutionExceptionfor a placeholder that cannot be resolved and has no default. Use it when a missing value is an error.override -
setRequiredProperties(
List< String> keys) → void -
Adds
keysto the properties validateRequiredProperties checks; keys added earlier stay.override -
toString(
) → String -
A string representation of this object.
inherited
-
validateRequiredProperties(
) → void -
Checks that every key given to setRequiredProperties has a value,
and throws
MissingRequiredPropertiesExceptionlisting all the missing ones at once. An application context calls it when it starts, before any bean is created.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited