java.lang.Object
io.helidon.config.ValueResolvingFilter
- All Implemented Interfaces:
ConfigFilter
A config filter that replaces all placeholders in a config value String with
their corresponding values looked up from the config.
For example:
message = "Hello ${name}!"
name = "Joachim"
will be resolved as:
message = "Hello Joachim!"
How to Activate This Filter
Use any of the following techniques to create aValueResolvingFilter and
use it for config look-ups.
- Programmatically:
- Invoke
ConfigFilters.valueResolving()to get a builder for the filter. - Optionally, invoke the filter builder's
failOnMissingReferencemethod (see below). - Invoke the builder's
buildmethod to create the filter. - Then, on the
Config.Builderbeing used to construct theConfiginstance, invokeConfig.Builder#addFilterpassing the just-created filter.
- Invoke
- Implicitly: Create or edit the file
io.helidon.config.ConfigFilteron the application's runtime classpath to contain this line:
The config system will then use the Java service loader mechanism to create and add this filter to everyio.helidon.config.ValueResolvingFilterConfig.Builderautomatically.
Handling Missing References
By default, references to tokens that are not present do not cause retrievals to fail. You can customize this behavior in several ways.- If you use
ConfigFilters.valueResolving()to get a builder for the filter, invoke thefailOnMissingReferencemethod on that builder before invoking the filter builder'sbuildmethod. - If you use
ConfigFilters.ValueResolvingBuilder.create(io.helidon.config.Config)to get the filter's builder, define this setting in theConfiginstance you pass to thefrommethod:"config.value-resolving-filter.fail-on-missing-reference" = true
orfalsewhich is the default. This sets the behavior for the single filter created from that builder. - If you use the Java service loader mechanism to create
ValueResolvingFilters for everyConfig.Builder, specify the following config setting in one of the config sources that composes the default config:"config.value-resolving-filter.fail-on-missing-reference" = true
orfalsewhich is the default. This sets the behavior for everyValueResolvingFiltercreated for which thefailOnMissingReferencevalue has not already been set, for example by invoking theConfigFilters.valueResolving().failOnMissingReference()method.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance of the filter with no explicit failOnMissing behavior set.ValueResolvingFilter(boolean failOnMissingReference) Creates an instance of filter with the specified behavior on missing references. -
Method Summary
Modifier and TypeMethodDescriptionapply(Config.Key key, String stringValue) Filters an elementary config value before it is made available to the application via theConfigAPI.voidInitializes the filter using theConfiginstance which the filter will affect onceConfig.Builder.buildcompletes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.helidon.config.spi.ConfigFilter
apply
-
Constructor Details
-
ValueResolvingFilter
public ValueResolvingFilter(boolean failOnMissingReference) Creates an instance of filter with the specified behavior on missing references.- Parameters:
failOnMissingReference- whether to fail when a referenced key is missing
-
ValueResolvingFilter
public ValueResolvingFilter()Creates an instance of the filter with no explicit failOnMissing behavior set.
-
-
Method Details
-
init
Description copied from interface:ConfigFilterInitializes the filter using theConfiginstance which the filter will affect onceConfig.Builder.buildcompletes.The config system propagates any thrown exception to the application so its invocation of
Config.Builder#buildfails.- Specified by:
initin interfaceConfigFilter- Parameters:
config-Configinstance under construction
-
apply
Description copied from interface:ConfigFilterFilters an elementary config value before it is made available to the application via theConfigAPI.- Specified by:
applyin interfaceConfigFilter- Parameters:
key- configurationkeyassociated with theConfignodestringValue- original value to be filtered, nevernull- Returns:
- original value or filtered (changed) value, never
null
-