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

AbstractPropertyResolver()

Properties

conversionService ↔ ConversionService
The service that converts values in PropertyResolver.getPropertyAs and in @ConfigurationProperties binding.
getter/setter pairoverride
escapeCharacter ← String?
The character that makes a placeholder prefix or separator literal (\${ is the text ${); \ unless changed. null turns 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. null turns 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 key as text, placeholders resolved, or defaultValue (null unless given) when no source has it.
override
getPropertyAs<T>(String key, {T? defaultValue}) → T?
The value of the property key converted to T, or defaultValue when no source has it.
override
getRawProperty(String key) → Object?
The stored value of key as it is, or null when there is none.
getRequiredProperty(String key) → String
The value of the property key as text, for settings the application cannot run without. Throws MissingPropertyException when no source has it.
override
getRequiredPropertyAs<T>(String key) → T
The value of the property key converted to T. Throws MissingPropertyException when no source has it (or it converts to null), and a ConversionException when 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} in text with 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} in text like resolvePlaceholders, but throws PlaceholderResolutionException for 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 keys to 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 MissingRequiredPropertiesException listing 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