- 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 of- override source;
- sources- instances of- configuration source;
- mappers- ordered list of mapper functions. It is also possible to- disableloading of- ConfigMapperProviders as a- service.
- parsers- ordered list of- configuration content parsers. It is also possible to- disableloading of- ConfigParsers as a- service.
- token reference resolving- a resolving of reference tokens in a key can be- disabled
- filters- ordered list of- configuration value filters. It is also possible to- disableloading of- ConfigFilters as a- service.
- caching- can be elementary configuration value processed by filter cached?
 In case of ConfigMapperProviders, 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 format
- meta-config.conf- meta configuration file in HOCON format
- meta-config.json- meta configuration file in JSON format
- meta-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 format
- application.conf- configuration file in HOCON format
- application.json- configuration file in JSON format
- application.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 SummaryModifier and TypeMethodDescriptionaddFilter(ConfigFilter configFilter) Registers aConfigFilterinstance that will be used byConfigto filter elementary value before it is returned to a user.addFilter(Function<Config, ConfigFilter> configFilterProvider) addFilter(Supplier<Function<Config, ConfigFilter>> configFilterSupplier) <T> Config.BuilderaddMapper(GenericType<T> type, Function<Config, T> mapper) Register a mapping function for specifiedGenericType.addMapper(ConfigMapperProvider configMapperProvider) <T> Config.BuilderRegisters mapping function for specifiedtype.addParser(ConfigParser configParser) Registers aConfigParserinstance that can be used by config system to parseConfigParser.ContentofParsableSource.addSource(ConfigSource source) Add a config source to the list of sources.default Config.BuilderaddSource(Supplier<? extends ConfigSource> source) Add a single config source to this builder.<T> Config.BuilderaddStringMapper(Class<T> type, Function<String, T> mapper) build()Builds new instance ofConfig.changesExecutor(Executor changesExecutor) Specifies "observe-on"Executorto 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 onConfigside.Disables use ofenvironment variables config source.Disables automatic registration of filters loaded as aservice.Disables any usage of resolving key tokens.Disables automatic registration of mappers viaConfigMapperProviderSPI loaded as aservice.Disables automatic registration of parsers loaded as aservice.Disables use ofsystem properties config source.Disables any 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.BuilderCheck if meta configuration is present and if so, update this builder using the meta configuration.overrides(Supplier<? extends OverrideSource> overridingSource) Sets the source of an override source.serviceRegistry(ServiceRegistry serviceRegistry) Configure an explicit service registry to use to discover services (config sources, parsers etc.).default Config.Buildersources(Supplier<? extends ConfigSource> configSource) Sets aConfigSourceinstance to be used as a source of configuration to be wrapped intoConfigAPI.default Config.Buildersources(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2) Sets an ordered pair ofConfigSourceinstances to be used as single source of configuration to be wrapped intoConfigAPI.default Config.Buildersources(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2, Supplier<? extends ConfigSource> configSource3) Sets an ordered trio ofConfigSourceinstances to be used as single source of configuration to be wrapped intoConfigAPI.sources(List<Supplier<? extends ConfigSource>> configSources) Sets ordered list ofConfigSourceinstance to be used as single source of configuration to be wrapped intoConfigAPI.
- 
Method Details- 
sourcesSets ordered list ofConfigSourceinstance to be used as single source of configuration to be wrapped intoConfigAPI.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 of following sources, in order: - environment variables config source
 Can disabled by- disableEnvironmentVariablesSource()
- system properties config sourceCan disabled by- disableSystemPropertiesSource()
- Source(s) specified by user in the method.
 - Parameters:
- configSources- ordered list of configuration sources
- Returns:
- an updated builder instance
- See Also:
 
- 
addSourceAdd a config source to the list of sources.- Parameters:
- source- to add
- Returns:
- updated builder instance
 
- 
mergingStrategyMerging 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
 
- 
addSourceAdd a single config source to this builder.- Parameters:
- source- config source to add
- Returns:
- updated builder instance
 
- 
sourcesSets aConfigSourceinstance to be used as a source of configuration to be wrapped intoConfigAPI.Target source is composed of configSourceand following sources (unless they are disabled) in order:- environment variables config source
 Can disabled by- disableEnvironmentVariablesSource()
- system properties config sourceCan disabled by- disableSystemPropertiesSource()
- Source(s) specified by user in the method.
 - Parameters:
- configSource- the only config source
- Returns:
- an updated builder instance
- See Also:
 
- 
sourcesdefault Config.Builder sources(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2) Sets an ordered pair ofConfigSourceinstances to be used as single source of configuration to be wrapped intoConfigAPI.Target source is of from configSourceand following sources (unless they are disabled) in order:- environment variables config source
 Can disabled by- disableEnvironmentVariablesSource()
- system properties config sourceCan disabled by- disableSystemPropertiesSource()
- Source(s) specified by user in the method.
 - Parameters:
- configSource- the first config source
- configSource2- the second config source
- Returns:
- an updated builder instance
- See Also:
 
- 
sourcesdefault Config.Builder sources(Supplier<? extends ConfigSource> configSource, Supplier<? extends ConfigSource> configSource2, Supplier<? extends ConfigSource> configSource3) Sets an ordered trio ofConfigSourceinstances to be used as single source of configuration to be wrapped intoConfigAPI.Target source is composed of config sources parameters and following sources (unless they are disabled) in order: - environment variables config source
 Can disabled by- disableEnvironmentVariablesSource()
- system properties config sourceCan disabled by- disableSystemPropertiesSource()
- Source(s) specified by user in the method.
 - Parameters:
- configSource- the first config source
- configSource2- the second config source
- configSource3- the third config source
- Returns:
- an updated builder instance
- See Also:
 
- 
overridesSets the source of an 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 higherweightto identify the current environment (i.e.env: testandpod: qwerty). The overrides are able to redefine values using wildcards (or without them). For exampletest.*.logging.level = FINEoverrideslogging.levelfor 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
 
- 
disableKeyResolvingConfig.Builder disableKeyResolving()Disables any 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
 
- 
failOnMissingKeyReferenceWhen 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:
 
- 
disableValueResolvingConfig.Builder disableValueResolving()Disables any 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
 
- 
failOnMissingValueReferenceWhen 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:
 
- 
disableEnvironmentVariablesSourceConfig.Builder disableEnvironmentVariablesSource()Disables use ofenvironment variables config source.- Returns:
- an updated builder instance
- See Also:
 
- 
disableSystemPropertiesSourceConfig.Builder disableSystemPropertiesSource()Disables use ofsystem properties config source.- Returns:
- an updated builder instance
- See Also:
 
- 
addMapperRegisters mapping function for specifiedtype. The last registration of sametypeoverwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a serviceviaConfigMapperProviderSPI unless it isdisabled.And the last option, built-in mappersare registered.- Type Parameters:
- T- type the- mapperis registered for
- Parameters:
- type- class of type the- mapperis registered for
- mapper- mapping function
- Returns:
- an updated builder instance
- See Also:
 
- 
addMapperRegister a mapping function for specifiedGenericType. This is useful for mappers that support specifically 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 for
- mapper- mapping function
- Returns:
- updated builder instance
 
- 
addStringMapperRegisters simpleFunctionfromStringfor specifiedtype. The last registration of sametypeoverwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a serviceviaConfigMapperProviderSPI, if notdisabled.And the last option, built-in mappersare registered.- Type Parameters:
- T- type the- mapperis registered for
- Parameters:
- type- class of type the- mapperis registered for
- mapper- mapper instance
- Returns:
- an updated builder instance
- See Also:
 
- 
addMapperRegisters aConfigMapperProviderwith a map ofStringto specifiedtype. The last registration of sametypeoverwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a serviceviaConfigMapperProviderSPI, if notdisabled.And the last option, built-in mappersare registered.- Parameters:
- configMapperProvider- mapper provider instance
- Returns:
- modified builder instance
- See Also:
 
- 
disableMapperServicesConfig.Builder disableMapperServices()Disables automatic registration of mappers viaConfigMapperProviderSPI loaded as aservice.Order of configuration mapper providers loaded as a service is defined by Weightannotation.Automatic registration of mappers as a service is enabled by default. - Returns:
- an updated builder instance
- See Also:
 
- 
addParserRegisters aConfigParserinstance that can be used by config system to parseConfigParser.ContentofParsableSource. 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:
 
- 
disableParserServicesConfig.Builder disableParserServices()Disables automatic registration of parsers loaded as aservice.Order of configuration parsers loaded as a service is defined by Weightannotation.Automatic registration of parsers as a service is enabled by default. - Returns:
- an updated builder instance
- See Also:
 
- 
addFilterRegisters aConfigFilterinstance that will be used byConfigto filter elementary value before it is returned to a user.Filters are applied in same order as was registered by this method, addFilter(Function)oraddFilter(Supplier)method.ConfigFilteris 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:
 
- 
addFilterRegisters aConfigFilterprovider as aFunction<Config,ConfigFilter>. An obtained filter will be used byConfigto 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. E.g. when this builder'sbuild()method creates theConfigor 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 of- Configto- ConfigFilter
- Returns:
- an updated builder instance
- See Also:
 
- 
addFilterRegisters aConfigFilterprovider as aSupplier<Function<Config,ConfigFilter>>. An obtained filter will be used byConfigto 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. E.g. when this builder'sbuild()method creates theConfigor 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 of- Configto- ConfigFilter
- Returns:
- an updated builder instance
- See Also:
 
- 
disableFilterServicesConfig.Builder disableFilterServices()Disables automatic registration of filters loaded as aservice.Order of configuration filters loaded as a service is defined by Weightannotation.Automatic registration of filters as a service is enabled by default. - Returns:
- an updated builder instance
- See Also:
 
- 
disableCachingConfig.Builder disableCaching()Disables caching of elementary configuration values onConfigside.Caching is about ConfigFilters. 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:
 
- 
changesExecutorSpecifies "observe-on"Executorto 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 of- Config.onChange(java.util.function.Consumer)
- Returns:
- an updated builder instance
- See Also:
 
- 
buildConfig build()Builds new instance ofConfig.- Specified by:
- buildin interface- Builder<Config.Builder,- Config> 
- Returns:
- new instance of Config.
 
- 
metaConfigCheck if meta configuration is present and if so, update this builder using the meta configuration.- Returns:
- updated builder instance
- See Also:
 
- 
configConfigure this config builder from meta configuration.The following configuration options are supported in a meta configuration file: 
 Config source configuration options:Meta configuration key default value description reference caching.enabled trueEnable or disable caching of results of filters. disableCaching()key-resolving.enabled trueEnable or disable resolving of placeholders in keys. disableKeyResolving()value-resolving.enabled trueEnable or disable resolving of placeholders in values. disableValueResolving()parsers.enabled trueEnable or disable parser services. disableParserServices()mappers.enabled trueEnable 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, propertiesConfigure config sources to be used by the application. This node contains the array of objects defining config sources addSource(io.helidon.config.spi.ConfigSource)
 Full meta configuration example: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 falseIf 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
 
- 
serviceRegistryConfigure an explicit service registry to use to discover services (config sources, parsers etc.).- Parameters:
- serviceRegistry- registry to use
- Returns:
- updated builder instance
 
 
-