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.Function<io.helidon.config.Config, java.lang.Boolean>)
.
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:
Configuration SPI
-
Interface Summary Interface Description Config ConfigurationConfig.Builder Config
Builder.Config.Context Context associated with specificConfig
node that allows to access the last loaded instance of the node or to request reloading of whole configuration.Config.Key Object represents fully-qualified key of config node.ConfigSources.MergingStrategy An algorithm for combining multipleConfigNode.ObjectNode
root nodes into a singleConfigNode.ObjectNode
root node.ConfigValue<T> A typed value of aConfig
node. -
Class Summary Class Description ConfigFilters Class provides access to built-inConfigFilter
implementations.ConfigFilters.ValueResolvingBuilder A builder for value reference resolving filter.ConfigHelper Common Configuration utilities.ConfigMappers Utility methods for converting configuration to Java types.ConfigParsers Provides access to built-inConfigParser
implementations.ConfigSources Provides access to built-inConfigSource
implementations.ConfigSources.CompositeBuilder Builder of aConfigSource
that encapsulates multiple separateConfigSource
s.ConfigSources.MapBuilder Builder of aConfigSource
based on aMap
containing config entries.ConfigValues Factory for config values.EnvironmentVariableAliases Provides configuration key aliases in an attempt to map to legal environment variable names.EnvironmentVariables Provides environment variables that include aliases enabling setting or overriding configuration with keys that are unlikely to be legal as environment variables.OverrideSources Class provides access to built-inOverrideSource
implementations.PollingStrategies Built-inPollingStrategy
implementations.PollingStrategies.FilesystemWatchBuilder A builder for a filesystem watch polling strategy.PollingStrategies.ScheduledBuilder A builder for a scheduled polling strategy.RetryPolicies Class provides access to built-inRetryPolicy
implementations.RetryPolicies.Builder A builder of the defaultRetryPolicy
. -
Enum Summary Enum Description Config.Type Configuration node types. -
Exception Summary Exception Description ConfigException Exception is thrown byConfig
implementations.ConfigMappingException Configuration value mapping exception.MissingValueException Exception representing a specific failures related to a missing configuration value.