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:
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.ConfigSourceRuntime The runtime of a config source.ConfigValue<T> A typed value of aConfig
node.MergeableNode Extension ofConfigNode
that supports merging with other nodes.ScheduledPollingStrategy.RecurringPolicy An SPI that allows users to define their own policy how to change the interval between scheduled ticking. -
Class Summary Class Description AbstractConfigSource A base implementation for config sources, that combines configuration from any type of a config source.AbstractConfigSourceBuilder<B extends AbstractConfigSourceBuilder<B,U>,U> 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
.AbstractNodeBuilderImpl.MergingKey Internal config node key useful during internal structure building.AbstractSource Source options as a super set of all possible combinations of source implementation.AbstractSourceBuilder<B extends AbstractSourceBuilder<B,U>,U> Base class for common builder methods of aSource
implementation.ClasspathConfigSource ConfigSource
implementation that loads configuration content from a resource on a classpath.ClasspathConfigSource.Builder Classpath ConfigSource Builder.ClasspathOverrideSource OverrideSource
implementation that loads override definitions from a resource on a classpath.ClasspathOverrideSource.Builder Classpath OverrideSource Builder.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.SystemPropertiesConfigSource System properties config source.ConfigSources.SystemPropertiesConfigSource.Builder A fluent API builder forConfigSources.SystemPropertiesConfigSource
.ConfigValues Factory for config values.DeprecatedConfig A utility class to handle configuration properties that should no longer be used.DirectoryConfigSource ConfigSource
implementation that loads configuration content from a directory on a filesystem.DirectoryConfigSource.Builder Common ancestor for config source builders, taking care of configurable options understood by the config module.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.FileConfigSource ConfigSource
implementation that loads configuration content from a file on a filesystem.FileConfigSource.Builder File ConfigSource Builder.FileOverrideSource OverrideSource
implementation that loads override definitions from a file on a filesystem.FileOverrideSource.Builder File OverrideSource Builder.FileSourceHelper Utilities for file-related source classes.FileSourceHelper.DataAndDigest Data and digest of a file.FileSystemWatcher This change watcher is backed byWatchService
to fire a polling event with every change on monitoredPath
.FileSystemWatcher.Builder Fluent API builder forFileSystemWatcher
.InMemoryOverrideSource In-memory implementation of override source.InMemoryOverrideSource.Builder Fluent API builder forInMemoryOverrideSource
.ListNodeBuilderImpl Implementation ofConfigNode.ListNode.Builder
.MapConfigSource ConfigSource
implementation based onMap<String, String>
.MapConfigSource.Builder Fluent API builder forMapConfigSource
.MapConfigSource.MapBuilder<T extends MapConfigSource.MapBuilder<T>> An abstract fluent API builder forMapConfigSource
.MetaConfig Meta configuration.MutabilitySupport Mutability support for file based sources.ObjectNodeBuilderImpl Implementation ofConfigNode.ObjectNode.Builder
.ObjectNodeImpl ImplementsConfigNode.ObjectNode
.OverrideConfigFilter A config filter that replaces values with a new ones of keys that matching withPattern
.OverrideSources Class provides access to built-inOverrideSource
implementations.PollingStrategies Built-inPollingStrategy
implementations.PollingStrategies.ScheduledBuilder A builder for a scheduled polling strategy.PrefixedConfigSource ConfigSource
implementation wraps another config source and add key prefix to original one.PropertiesConfigParser ConfigParser
implementation that parses Java Properties content.RetryPolicies Class provides access to built-inRetryPolicy
implementations.ScheduledPollingStrategy A strategy which allows the user to schedule periodically fired polling event.ScheduledPollingStrategy.Builder A fluent API builder forScheduledPollingStrategy
.ScheduledPollingStrategy.RecurringPolicy.AdaptiveBuilder 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()
.ScheduledPollingStrategy.RegularRecurringPolicy Regular polling strategy implementation.SimpleRetryPolicy A default retry policy implementation withScheduledExecutorService
.SimpleRetryPolicy.Builder Fluent API builder forSimpleRetryPolicy
.UrlConfigSource ConfigSource
implementation that loads configuration content from specified endpoint URL.UrlConfigSource.Builder Url ConfigSource Builder.UrlOverrideSource OverrideSource
implementation that loads configuration override content from specified endpoint URL.UrlOverrideSource.Builder Url Override Source Builder.ValueNodeImpl ImplementsConfigNode.ValueNode
.ValueResolvingFilter A config filter that replaces all placeholders in a config value String with their corresponding values looked up from the config. -
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.