Package io.helidon.config
Loading a Configuration
The program loads a configuration from either the default sources (usingConfig.create()) or
from specified ConfigSources
(using Config.Builder).
The default sources include all of the following, in order:
- environment variables
- Java system properties
- the first of the following (if any) on the classpath:
application.yamlapplication.conf(HOCON format)application.jsonapplication.properties
ConfigParser.
See Config for further information.
Using a Configuration Tree
This overview summarizes how a program can use loaded configuration. For full details see theConfig class.
Once loaded, configuration information is available to the program as Config
nodes in a tree. Each node has:
- a name,
- a
Config.Keyrepresenting the full path from the root to the node, and - some content.
Config.type() method
returns an enum value Config.Type that tells how the
program should interpret the content of the node.
| Type | Meaning | Useful Config Methods |
|---|---|---|
| VALUE | value node with an optional direct String value |
|
| LIST | list of indexed nodes with an optional "direct" value | Config.asList(java.lang.Class),
Config.asNodeList() |
| OBJECT | object node with, possibly, child nodes and an optional "direct" value | Config.asNodeList() |
Configuration Values and Types
While each node's direct value is accessible as anOptional<String>, the program can also
have the node convert its String value to a typed ConfigValue using methods such as
Config.asString(), Config.asLong() etc.
The program can provide its own ConfigMapperProvider implementations
to deal with more complicated value mapping needs. See also Config.Builder.addStringMapper(java.lang.Class<T>, java.util.function.Function<java.lang.String, T>)
and Config.Builder.addMapper(java.lang.Class, java.util.function.Function).
Navigation
The program can retrieve a node's child nodes as aList.
The program can navigate directly to a given subnode using the
Config.get(java.lang.String) method and passing the dotted path to the subnode.
The Config.traverse() methods return a stream of nodes
in depth-first order.
Bulk Retrieval of Values
The program can retrieve aMap of dotted names to String values
for a node's entire subtree using Config.asMap().
Monitoring Changes
The program can react to configuration changes by passing a listener toConfig.onChange(java.util.function.Consumer).
Converting Configuration to Java Types
TheConfig class provides many methods for converting config
String values to Java primitives and simple Java types, as well as
mapping parts of the config tree to Lists and Maps.
The application can convert config data to arbitrary types using the
Config.as(java.lang.Class) and Config.as(java.util.function.Function)
methods, and can provide its own conversions to handle
custom types by implementing a mapping function and registering it
with a Config.Builder using the Config.Builder.addMapper(java.lang.Class<T>, java.util.function.Function<io.helidon.config.Config, T>) method.
If the Config.as method finds no matching registered mapper it will throw
a ConfigMappingException.
Support for automated mapping to types is available in module config-beans.
- See Also:
-
ClassDescriptionA base implementation for config sources, that combines configuration from any type of a config source.Common ancestor for config source builders, taking care of configurable options understood by the config module.AbstractNodeBuilderImpl<ID,
B> Common implementation ofConfigNode.ListNode.BuilderandConfigNode.ObjectNode.Builder.Internal config node key useful during internal structure building.Source options as a super set of all possible combinations of source implementation.Base class for common builder methods of aSourceimplementation.ConfigSourceimplementation that loads configuration content from a resource on a classpath.Classpath ConfigSource Builder.OverrideSourceimplementation that loads override definitions from a resource on a classpath.Classpath OverrideSource Builder.ConfigurationConfigBuilder.Context associated with specificConfignode that allows to access the last loaded instance of the node or to request reloading of whole configuration.Object represents fully-qualified key of config node.Configuration node types.Exception is thrown byConfigimplementations.Class provides access to built-inConfigFilterimplementations.A builder for value reference resolving filter.Common Configuration utilities.Configuration item policy.Fluent API builder forConfigItem.ConfigItem.BuilderBase<BUILDER extends ConfigItem.BuilderBase<BUILDER,PROTOTYPE>, PROTOTYPE extends ConfigItem> Fluent API builder base forConfigItem.Generated implementation of the prototype, can be extended by descendant prototype implementations.Utility methods for converting configuration to Java types.Configuration value mapping exception.Provides access to built-inConfigParserimplementations.Activator forConfigProducer.The runtime of a config source.Provides access to built-inConfigSourceimplementations.System properties config source.A fluent API builder forConfigSources.SystemPropertiesConfigSource.ConfigValue<T>A typed value of aConfignode.Factory for config values.A utility class to handle configuration properties that should no longer be used.ConfigSourceimplementation that loads configuration content from a directory on a filesystem.A fluent API builder forDirectoryConfigSource.Provides configuration key aliases in an attempt to map to legal environment variable names.Provides environment variables that include aliases enabling setting or overriding configuration with keys that are unlikely to be legal as environment variables.ConfigSourceimplementation that loads configuration content from a file on a filesystem.File ConfigSource Builder.OverrideSourceimplementation that loads override definitions from a file on a filesystem.File OverrideSource Builder.Utilities for file-related source classes.Data and digest of a file.This change watcher is backed byWatchServiceto fire a polling event with every change on monitoredPath.Fluent API builder forFileSystemWatcher.Service loader provider implementation for common config.Generated ModuleComponent.In-memory implementation of override source.Fluent API builder forInMemoryOverrideSource.Implementation ofConfigNode.ListNode.Builder.ConfigSourceimplementation based onMap<String, String>.Fluent API builder forMapConfigSource.MapConfigSource.MapBuilder<T extends MapConfigSource.MapBuilder<T>>An abstract fluent API builder forMapConfigSource.Extension ofConfigNodethat supports merging with other nodes.Meta configuration.Exception representing a specific failures related to a missing configuration value.Mutability support for file based sources.Implementation ofConfigNode.ObjectNode.Builder.ImplementsConfigNode.ObjectNode.A config filter that replaces values with a new ones of keys that matching withPattern.Class provides access to built-inOverrideSourceimplementations.Built-inPollingStrategyimplementations.A builder for a scheduled polling strategy.ConfigSourceimplementation wraps another config source and add key prefix to original one.ConfigParserimplementation that parses Java Properties content.Class provides access to built-inRetryPolicyimplementations.A strategy which allows the user to schedule periodically fired polling event.A fluent API builder forScheduledPollingStrategy.An SPI that allows users to define their own policy how to change the interval between scheduled ticking.Creates a builder ofScheduledPollingStrategy.RecurringPolicywith an ability to change the behaviour, with a boundaries and the possibility to react to feedback given byScheduledPollingStrategy.RecurringPolicy.shorten()orScheduledPollingStrategy.RecurringPolicy.lengthen().Regular polling strategy implementation.A default retry policy implementation withScheduledExecutorService.Fluent API builder forSimpleRetryPolicy.ConfigSourceimplementation that loads configuration content from specified endpoint URL.Url ConfigSource Builder.OverrideSourceimplementation that loads configuration override content from specified endpoint URL.Url Override Source Builder.ImplementsConfigNode.ValueNode.A config filter that replaces all placeholders in a config value String with their corresponding values looked up from the config.