Package io.helidon.config
Loading a Configuration
The program loads a configuration from either the default sources (usingConfig.create()
) or
from specified ConfigSource
s
(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.yaml
application.conf
(HOCON format)application.json
application.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.Key
representing 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 List
s and Map
s.
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.Builder
andConfigNode.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 aSource
implementation.ConfigSource
implementation that loads configuration content from a resource on a classpath.Classpath ConfigSource Builder.OverrideSource
implementation that loads override definitions from a resource on a classpath.Classpath OverrideSource Builder.ConfigurationConfig
Builder.Context associated with specificConfig
node 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 byConfig
implementations.Class provides access to built-inConfigFilter
implementations.A builder for value reference resolving filter.Common Configuration utilities.Utility methods for converting configuration to Java types.Configuration value mapping exception.Provides access to built-inConfigParser
implementations.The runtime of a config source.Provides access to built-inConfigSource
implementations.System properties config source.A fluent API builder forConfigSources.SystemPropertiesConfigSource
.ConfigValue<T>A typed value of aConfig
node.Factory for config values.A utility class to handle configuration properties that should no longer be used.ConfigSource
implementation that loads configuration content from a directory on a filesystem.Common ancestor for config source builders, taking care of configurable options understood by the config module.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.ConfigSource
implementation that loads configuration content from a file on a filesystem.File ConfigSource Builder.OverrideSource
implementation 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 byWatchService
to fire a polling event with every change on monitoredPath
.Fluent API builder forFileSystemWatcher
.In-memory implementation of override source.Fluent API builder forInMemoryOverrideSource
.Implementation ofConfigNode.ListNode.Builder
.ConfigSource
implementation based onMap<String, String>
.Fluent API builder forMapConfigSource
.MapConfigSource.MapBuilder<T extends MapConfigSource.MapBuilder<T>>An abstract fluent API builder forMapConfigSource
.Extension ofConfigNode
that 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-inOverrideSource
implementations.Built-inPollingStrategy
implementations.A builder for a scheduled polling strategy.ConfigSource
implementation wraps another config source and add key prefix to original one.ConfigParser
implementation that parses Java Properties content.Filter properties with provided and default filter pattern.Class provides access to built-inRetryPolicy
implementations.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.RecurringPolicy
with 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
.ConfigSource
implementation that loads configuration content from specified endpoint URL.Url ConfigSource Builder.OverrideSource
implementation 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.