- All Superinterfaces:
Builder<Config.Builder,
,Config> Supplier<Config>
- Enclosing interface:
- Config
Config
Builder.
A factory for a Config
object.
The application can set the following characteristics:
overrides
- instance ofoverride source
;sources
- instances ofconfiguration source
;mappers
- ordered list of mapper functions. It is also possible todisable
loading ofConfigMapperProvider
s as aservice
.parsers
- ordered list ofconfiguration content parsers
. It is also possible todisable
loading ofConfigParser
s as aservice
.token reference resolving
- a resolving of reference tokens in a key can bedisabled
filters
- ordered list ofconfiguration value filters
. It is also possible todisable
loading ofConfigFilter
s as aservice
.caching
- can be elementary configuration value processed by filter cached?
In case of ConfigMapperProvider
s, if there is no one that could be used to map appropriate type
,
the mapping attempt throws a ConfigMappingException
.
A more sophisticated approach can be achieved using the "config beans" module, that provides reflection access and mapping for static factory methods, constructors, builder patterns and more.
If a ConfigSource
is not specified, following default config source is used. Same as Config.create()
uses.
It builds composite config source from following sources, checked in order:
- Tries to load configuration from meta one of following meta configuration files on classpath, in order:
meta-config.yaml
- meta configuration file in YAML formatmeta-config.conf
- meta configuration file in HOCON formatmeta-config.json
- meta configuration file in JSON formatmeta-config.properties
- meta configuration file in Java Properties format
- Otherwise, configuration consists of:
Environment variables
;- or else
System properties
- one of following files on classpath, checked in order:
application.yaml
- configuration file in YAML formatapplication.conf
- configuration file in HOCON formatapplication.json
- configuration file in JSON formatapplication.properties
- configuration file in Java Properties format
ConfigParser
available
that supports appropriate media type
.
Available parser means that the parser:
- is loaded as a service using
ServiceLoader
; - or if it does not exist, a config core built-in parser is used, if exists.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddFilter
(ConfigFilter configFilter) Registers aConfigFilter
instance that will be used byConfig
to filter elementary value before it is returned to a user.addFilter
(Function<Config, ConfigFilter> configFilterProvider) addFilter
(Supplier<Function<Config, ConfigFilter>> configFilterSupplier) <T> Config.Builder
addMapper
(GenericType<T> type, Function<Config, T> mapper) Register a mapping function for specifiedGenericType
.addMapper
(ConfigMapperProvider configMapperProvider) <T> Config.Builder
Registers mapping function for specifiedtype
.addParser
(ConfigParser configParser) Registers aConfigParser
instance that can be used by config system to parse parseConfigParser.Content
ofParsableSource
.addSource
(ConfigSource source) Add a config source to the list of sources.default Config.Builder
addSource
(Supplier<? extends ConfigSource> source) Add a single config source to this builder.<T> Config.Builder
addStringMapper
(Class<T> type, Function<String, T> mapper) build()
Builds new instance ofConfig
.changesExecutor
(Executor changesExecutor) Specifies "observe-on"Executor
to be used byConfig.onChange(java.util.function.Consumer)
to deliver new Config instance.Configure this config builder from meta configuration.Disables caching of elementary configuration values onConfig
side.Disables use ofenvironment variables config source
.Disables automatic registration of filters loaded as aservice
.Disables an usage of resolving key tokens.Disables automatic registration of mappers viaConfigMapperProvider
SPI loaded as aservice
.Disables automatic registration of parsers loaded as aservice
.Disables use ofsystem properties config source
.Disables an usage of resolving value tokens.failOnMissingKeyReference
(boolean shouldFail) When key resolving is enabled and a reference cannot be resolved, should we fail, or use the key verbatim.failOnMissingValueReference
(boolean shouldFail) When value resolving is enabled and a reference cannot be resolved, should we fail, or use the value verbatim.mergingStrategy
(MergingStrategy strategy) Merging Strategy to use when more than one config source is used.default Config.Builder
Check if meta configuration is present and if so, update this builder using the meta configuration.overrides
(Supplier<? extends OverrideSource> overridingSource) Sets source of a override source.default Config.Builder
sources
(Supplier<? extends ConfigSource> configSource) Sets aConfigSource
instance to be used as a source of configuration to be wrapped intoConfig
API.default Config.Builder
sources
(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2) Sets an ordered pair ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.default Config.Builder
sources
(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2, Supplier<? extends ConfigSource> configSource3) Sets an ordered trio ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.sources
(List<Supplier<? extends ConfigSource>> configSources) Sets ordered list ofConfigSource
instance to be used as single source of configuration to be wrapped intoConfig
API.
-
Method Details
-
sources
Sets ordered list ofConfigSource
instance to be used as single source of configuration to be wrapped intoConfig
API.Configuration sources found earlier in the list are considered to have a higher priority than the latter ones. I.e., when resolving a value of a key, the sources are consulted in the order they have been provided and as soon as the value is found in a configuration source, the value immediately is returned without consulting any of the remaining configuration sources in the prioritized collection.
Target source is composed from following sources, in order:
environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSources
- ordered list of configuration sources- Returns:
- an updated builder instance
- See Also:
-
addSource
Add a config source to the list of sources.- Parameters:
source
- to add- Returns:
- updated builder instance
-
mergingStrategy
Merging Strategy to use when more than one config source is used.- Parameters:
strategy
- strategy to use, defaults to a strategy where a value for first source wins over values from later sources- Returns:
- updated builder instance
-
addSource
Add a single config source to this builder.- Parameters:
source
- config source to add- Returns:
- updated builder instance
-
sources
Sets aConfigSource
instance to be used as a source of configuration to be wrapped intoConfig
API.Target source is composed from
configSource
and following sources (unless they are disabled) in order:environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSource
- the only config source- Returns:
- an updated builder instance
- See Also:
-
sources
default Config.Builder sources(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2) Sets an ordered pair ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.Target source is composed from
configSource
and following sources (unless they are disabled) in order:environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSource
- the first config sourceconfigSource2
- the second config source- Returns:
- an updated builder instance
- See Also:
-
sources
default Config.Builder sources(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2, Supplier<? extends ConfigSource> configSource3) Sets an ordered trio ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.Target source is composed from config sources parameters and following sources (unless they are disabled) in order:
environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSource
- the first config sourceconfigSource2
- the second config sourceconfigSource3
- the third config source- Returns:
- an updated builder instance
- See Also:
-
overrides
Sets source of a override source.The feature allows user to override existing values with other ones, specified by wildcards. Default values might be defined with key token references (i.e.
$env.$pod.logging.level: INFO
) that might be overridden by a config source with a higher priority to identify the current environment (i.e.env: test
andpod: qwerty
. The overrides are able to redefine values using wildcards (or without them). For exampletest.*.logging.level = FINE
overrideslogging.level
for all pods in test environment.Override definitions are applied before any
filter
.- Parameters:
overridingSource
- a source with overriding key patterns and assigned values- Returns:
- an updated builder instance
-
disableKeyResolving
Config.Builder disableKeyResolving()Disables an usage of resolving key tokens.A key can contain tokens starting with
$
(i.e. $host.$port), that are resolved by default and tokens are replaced with a value of the key with the token as a key.- Returns:
- an updated builder instance
-
failOnMissingKeyReference
When key resolving is enabled and a reference cannot be resolved, should we fail, or use the key verbatim. Defaults tofalse
, so key resolving does not fail when a reference is missing.- Parameters:
shouldFail
- whether to fail when key reference cannot be resolved- Returns:
- updated builder
- See Also:
-
disableValueResolving
Config.Builder disableValueResolving()Disables an usage of resolving value tokens.A value can contain tokens enclosed in
${}
(i.e. ${name}), that are resolved by default and tokens are replaced with a value of the key with the token as a key.By default a value resolving filter is added to configuration. When this method is called, the filter will not be added and value resolving will be disabled
- Returns:
- an updated builder instance
-
failOnMissingValueReference
When value resolving is enabled and a reference cannot be resolved, should we fail, or use the value verbatim. Defaults tofalse
, so value resolving does not fail when a reference is missing.- Parameters:
shouldFail
- whether to fail when value reference cannot be resolved- Returns:
- updated builder
- See Also:
-
disableEnvironmentVariablesSource
Config.Builder disableEnvironmentVariablesSource()Disables use ofenvironment variables config source
.- Returns:
- an updated builder instance
- See Also:
-
disableSystemPropertiesSource
Config.Builder disableSystemPropertiesSource()Disables use ofsystem properties config source
.- Returns:
- an updated builder instance
- See Also:
-
addMapper
Registers mapping function for specifiedtype
. The last registration of sametype
overwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a
service
viaConfigMapperProvider
SPI unless it isdisabled
.And the last option,
built-in mappers
are registered.- Type Parameters:
T
- type themapper
is registered for- Parameters:
type
- class of type themapper
is registered formapper
- mapping function- Returns:
- an updated builder instance
- See Also:
-
addMapper
Register a mapping function for specifiedGenericType
. This is useful for mappers that support specificly typed generics, such asMap<String, Integer>
orSet<Foo<Bar>>
. To support mappers that can map any type (e.g. all cases ofMap<String, V>
), useaddMapper(ConfigMapperProvider)
as it gives you full control over which types are supported, throughConfigMapperProvider.mapper(GenericType)
.- Type Parameters:
T
- type of the result- Parameters:
type
- generic type to register a mapper formapper
- mapping function- Returns:
- updated builder instance
-
addStringMapper
Registers simpleFunction
fromString
for specifiedtype
. The last registration of sametype
overwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a
service
viaConfigMapperProvider
SPI, if notdisabled
.And the last option,
built-in mappers
are registered.- Type Parameters:
T
- type themapper
is registered for- Parameters:
type
- class of type themapper
is registered formapper
- mapper instance- Returns:
- an updated builder instance
- See Also:
-
addMapper
Registers aConfigMapperProvider
with a map ofString
to specifiedtype
. The last registration of sametype
overwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a
service
viaConfigMapperProvider
SPI, if notdisabled
.And the last option,
built-in mappers
are registered.- Parameters:
configMapperProvider
- mapper provider instance- Returns:
- modified builder instance
- See Also:
-
disableMapperServices
Config.Builder disableMapperServices()Disables automatic registration of mappers viaConfigMapperProvider
SPI loaded as aservice
.Order of configuration mapper providers loaded as a service is defined by
Priority
annotation.Automatic registration of mappers as a service is enabled by default.
- Returns:
- an updated builder instance
- See Also:
-
addParser
Registers aConfigParser
instance that can be used by config system to parse parseConfigParser.Content
ofParsableSource
. ParsersConfigParser.supportedMediaTypes()
is queried in same order as was registered by this method. Programmatically registered parsers have priority over other options.As another option, parsers are loaded automatically as a
service
, if notdisabled
.- Parameters:
configParser
- parser instance- Returns:
- an updated builder instance
- See Also:
-
disableParserServices
Config.Builder disableParserServices()Disables automatic registration of parsers loaded as aservice
.Order of configuration parsers loaded as a service is defined by
Priority
annotation.Automatic registration of parsers as a service is enabled by default.
- Returns:
- an updated builder instance
- See Also:
-
addFilter
Registers aConfigFilter
instance that will be used byConfig
to filter elementary value before it is returned to a user.Filters are applied in same order as was registered by the this method,
addFilter(Function)
oraddFilter(Supplier)
method.ConfigFilter
is actually aBiFunction
<String
,String
,String
> where the first input parameter is the config key, the second is the original value and the result is the new value. So the filter can be added as simply as:Config.builder() .addFilter((key, originalValue) -> originalValue.toUpperCase()) .build();
The config system will automatically load filters defined as aservice
, unlessdisabled
.- Parameters:
configFilter
- filter instance- Returns:
- an updated builder instance
- See Also:
-
addFilter
Registers aConfigFilter
provider as aFunction
<Config
,ConfigFilter
>. An obtained filter will be used byConfig
to filter elementary value before it is returned to a user.Filters are applied in same order as was registered by the
addFilter(ConfigFilter)
, this method, oraddFilter(Supplier)
method.Registered provider's
Function.apply(Object)
method is called every time the new Config is created. Eg. when this builder'sbuild()
method creates theConfig
or when the newConfig.onChange(java.util.function.Consumer)
is fired with new Config instance with its own filter instance is created.- Parameters:
configFilterProvider
- a config filter provider as a function ofConfig
toConfigFilter
- Returns:
- an updated builder instance
- See Also:
-
addFilter
Registers aConfigFilter
provider as aSupplier
<Function
<Config
,ConfigFilter
>>. An obtained filter will be used byConfig
to filter elementary value before it is returned to a user.Filters are applied in same order as was registered by the
addFilter(ConfigFilter)
,addFilter(Function)
, or this method.Registered provider's
Function.apply(Object)
method is called every time the new Config is created. Eg. when this builder'sbuild()
method creates theConfig
or when the newConfig.onChange(java.util.function.Consumer)
change event is fired with new Config instance with its own filter instance is created.- Parameters:
configFilterSupplier
- a config filter provider as a supplier of a function ofConfig
toConfigFilter
- Returns:
- an updated builder instance
- See Also:
-
disableFilterServices
Config.Builder disableFilterServices()Disables automatic registration of filters loaded as aservice
.Order of configuration filters loaded as a service is defined by
Priority
annotation.Automatic registration of filters as a service is enabled by default.
- Returns:
- an updated builder instance
- See Also:
-
disableCaching
Config.Builder disableCaching()Disables caching of elementary configuration values onConfig
side.Caching is about
ConfigFilter
s. With disabled caching, registered filters are applied always you access elementary configuration value. With enabled caching, registered filters are applied just once per unique config node (key). Repeated access of already filtered key directly returns already cached value.Caching is enabled by default.
- Returns:
- an updated builder instance
- See Also:
-
changesExecutor
Specifies "observe-on"Executor
to be used byConfig.onChange(java.util.function.Consumer)
to deliver new Config instance. Executor is also used to process reloading of config from appropriatesource
.By default dedicated thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available is used.
- Parameters:
changesExecutor
- the executor to use for async delivery ofConfig.onChange(java.util.function.Consumer)
- Returns:
- an updated builder instance
- See Also:
-
build
Config build()Builds new instance ofConfig
.- Specified by:
build
in interfaceBuilder<Config.Builder,
Config> - Returns:
- new instance of
Config
.
-
metaConfig
Check if meta configuration is present and if so, update this builder using the meta configuration.- Returns:
- updated builder instance
- See Also:
-
config
Configure this config builder from meta configuration.The following configuration options are supported in a meta configuration file:
Meta configuration key default value description reference caching.enabled true
Enable or disable caching of results of filters. disableCaching()
key-resolving.enabled true
Enable or disable resolving of placeholders in keys. disableKeyResolving()
value-resolving.enabled true
Enable or disable resolving of placeholders in values. disableValueResolving()
parsers.enabled true
Enable or disable parser services. disableParserServices()
mappers.enabled true
Enable or disable mapper services. disableMapperServices()
override-source none Configure an override source. Same as config source configuration (see below) overrides(java.util.function.Supplier)
sources Default config sources are prefixed application
, and suffix is the first available ofyaml, conf, json, properties
Configure config sources to be used by the application. This node contains the array of objects defining config sources addSource(io.helidon.config.spi.ConfigSource)
Config source key default value description reference type Type of a config source - a string supported by a provider. MetaConfigurableProvider.create(String, Config)
multi-source false
If set to true, the provider creates more than one config source to be added ConfigSourceProvider.createMulti(String, Config)
properties Configuration options to configure the config source (meta configuration of a source) MetaConfigurableProvider.create(String, Config)
,MetaConfig.configSource(Config)
properties.optional false Config sources can be configured to be optional Source.optional()
properties.polling-strategy Some config sources can have a polling strategy defined PollableSource.Builder.pollingStrategy(io.helidon.config.spi.PollingStrategy)
,MetaConfig.pollingStrategy(Config)
properties.change-watcher Some config sources can have a change watcher defined WatchableSource.Builder.changeWatcher(io.helidon.config.spi.ChangeWatcher)
,MetaConfig.changeWatcher(Config)
properties.retry-policy Config sources can have a retry policy defined Source.retryPolicy()
,MetaConfig.retryPolicy(Config)
sources: - type: "system-properties" - type: "environment-variables" - type: "file" properties: optional: true path: "conf/dev-application.yaml" polling-strategy: type: "regular" retry-policy: type: "repeat" properties: retries: 5 - type: "classpath" properties: optional: true resource: "application.yaml"
- Parameters:
metaConfig
- meta configuration to set this builder up- Returns:
- updated builder from meta configuration
-