ConfigurablePropertyResolver class abstract interface

A PropertyResolver whose behaviour can be set: the conversion service, the placeholder syntax, and keys that must be present.

ConfigurableEnvironment is one, so these settings are made on the environment while the application starts, usually from an EnvironmentPostProcessor. Most applications never change them; the most useful part is setRequiredProperties with validateRequiredProperties, which fails the start early and clearly when a key the application needs is missing.

// A tool that reads `Level` values and cannot run without `app.name`:
// the last call throws, listing every missing key.
final ConfigurablePropertyResolver resolver = StandardEnvironment()
  ..conversionService = (DefaultConversionService()..addEnum(Level.values))
  ..ignoreUnresolvableNestedPlaceholders = true
  ..setRequiredProperties(['app.name']);
resolver.validateRequiredProperties();

Spring (Java):

ConfigurableEnvironment resolver = new StandardEnvironment();
resolver.setConversionService(new DefaultConversionService());
resolver.setIgnoreUnresolvableNestedPlaceholders(true);
resolver.setRequiredProperties("app.name");
resolver.validateRequiredProperties();
Implemented types

Properties

conversionService ↔ ConversionService
The service that converts values in PropertyResolver.getPropertyAs and in @ConfigurationProperties binding.
getter/setter pair
escapeCharacter ← String?
The character that makes a placeholder prefix or separator literal (\${ is the text ${); \ unless changed. null turns escaping off.
no getter
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 getter
placeholderPrefix ← String
The text that opens a placeholder; ${ unless changed.
no getter
placeholderSuffix ← String
The text that closes a placeholder; } unless changed.
no getter
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 getter

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".
inherited
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.
inherited
getPropertyAs<T>(String key, {T? defaultValue}) → T?
The value of the property key converted to T, or defaultValue when no source has it.
inherited
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.
inherited
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.
inherited
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.
inherited
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.
inherited
setRequiredProperties(List<String> keys) → void
Adds keys to the properties validateRequiredProperties checks; keys added earlier stay.
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.

Operators

operator ==(Object other) → bool
The equality operator.
inherited