Package io.helidon.config.spi
Interface ConfigSource
-
- All Superinterfaces:
AutoCloseable
,Changeable<ConfigNode.ObjectNode>
,Source<ConfigNode.ObjectNode>
,Supplier<ConfigSource>
- All Known Implementing Classes:
AbstractConfigSource
,AbstractParsableConfigSource
,EtcdConfigSource
,GitConfigSource
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ConfigSource extends Source<ConfigNode.ObjectNode>, Supplier<ConfigSource>
Source
of configuration.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static ConfigSource
create(Config metaConfig)
Initializes aConfigSource
from meta-configuration.default ConfigSource
get()
default void
init(ConfigContext context)
Initialize the config source with aConfigContext
.-
Methods inherited from interface io.helidon.config.spi.Source
changes, close, description, load
-
-
-
-
Method Detail
-
create
static ConfigSource create(Config metaConfig) throws ConfigMappingException, MissingValueException
Initializes aConfigSource
from meta-configuration.Meta-config can contain the following top level properties to define one or more
ConfigSource
s:type
- specifies the built-in configuration type (environment-variables, system-properties, directory, file, url, prefixed, classpath) or the custom config types of theConfigSource
being defined.class
- fully-qualified class name of one of:- a
ConfigSource
implementation, - a
Config.Builder
implementation with abuild()
method that returns aConfigSource
instance.
- a
type
orclass
but not both. If the meta-config specifies both the config system ignores theclass
information.As the config system loads configuration it uses mappers to convert the raw data into Java types. See
ConfigMapperProvider
for details about mapping.The meta-config can modify a
type
orclass
source declaration usingproperties
. SeeAbstractParsableConfigSource.Builder.init(Config)
for the available properties for types other thansystem-properties
andenvironment-variables
(which do not supportproperties
settings).Predefined Configuration Source Types Source Type Further Information Mandatory Properties system-properties
ConfigSources.systemProperties()
none environment-variables
ConfigSources.environmentVariables()
none classpath
ConfigSources.classpath(String)
resource
file
ConfigSources.file(String)
path
directory
ConfigSources.directory(String)
path
url
ConfigSources.url(URL)
url
prefixed
ConfigSources.prefixed(String, Supplier)
key
type
orclass
properties
sources = [ { type = "environment-variables" } { type = "system-properties" } { type = "directory" properties { path = "conf/secrets" media-type-mapping { yaml = "application/x-yaml" password = "application/base64" } polling-strategy { type = "regular" properties { interval = "PT15S" } } } } { type = "url" properties { url = "http://config-service/my-config" media-type = "application/hocon" optional = true retry-policy { type = "repeat" properties { retries = 3 } } } } { type = "file" properties { path = "conf/config.yaml" polling-strategy { type = "watch" } } } { type = "prefixed" properties { key = "app" type = "classpath" properties { resource = "app.yaml" } } } { type = "classpath" properties { resource = "default.yaml" } } ]
The example refers to the built-inpolling-strategy
typesregular
andwatch
. SeePollingStrategy
for details about all supported properties and custom implementation support. It also shows the built-inretry-policy
typerepeat
. SeeRetryPolicy
for more information.Custom Sources and Source Types
Custom Configuration Sources
The application can define a custom config source usingclass
instead oftype
in the meta-configuration. The referenced class must implement eitherConfigSource
orConfig.Builder
. If the custom implementation extendsAbstractParsableConfigSource.Builder
then the config system will invoke itsinit
method passing aConfig
object representing the information from the meta-configuration for that custom source. The implementation can then use the relevant properties to load and manage the configuration from the origin.Custom Configuration Source Types
The application can also add a custom source type to the list of built-in source types. The config system looks for the resourceMETA-INF/resources/meta-config-sources.properties
on the classpath and uses its contents to define custom source types. For each property the name is a new custom source type and the value is the fully-qualified class name of the customConfigSource
or a builder for a customConfigSource
.For example, the module
helidon-config-git
includes the resourceMETA-INF/resources/meta-config-sources.properties
containinggit = io.helidon.config.git.GitConfigSourceBuilder
This defines the new source typegit
which can then be referenced from meta-configuration this way:{ type = "git" properties { path = "application.conf" directory = "/app-config/" } }
- Parameters:
metaConfig
- meta-configuration used to initialize theConfigSource
- Returns:
ConfigSource
described bymetaConfig
- Throws:
MissingValueException
- if the configuration tree does not contain all expected sub-nodes required by the mapper implementation to provide an instance of the corresponding Java type.ConfigMappingException
- if the mapper fails to map the (existing) configuration tree represented by the supplied configuration node to an instance of the given Java type- See Also:
ConfigSources.load(Supplier[])
,ConfigSources.load(Config)
-
get
default ConfigSource get()
- Specified by:
get
in interfaceSupplier<ConfigSource>
-
init
default void init(ConfigContext context)
Initialize the config source with aConfigContext
.The method is executed during
Config
bootstrapping byConfig.Builder
.- Parameters:
context
- a config context
-
-