@FunctionalInterface public interface ConfigSource extends Source<ConfigNode.ObjectNode>, Supplier<ConfigSource>
Source of configuration.Config.Builder#sources(Supplier),
Config.Builder#sources(Supplier, Supplier),
Config.Builder#sources(Supplier, Supplier, Supplier),
Config.Builder#sources(java.util.List),
AbstractConfigSource,
AbstractParsableConfigSource,
ConfigSources - access built-in implementations.| Modifier and Type | Method and Description |
|---|---|
static ConfigSource |
create(Config metaConfig)
Initializes a
ConfigSource from meta-configuration. |
default ConfigSource |
get() |
default void |
init(ConfigContext context)
Initialize the config source with a
ConfigContext. |
changes, close, description, loadstatic ConfigSource create(Config metaConfig) throws ConfigMappingException, MissingValueException
ConfigSource from meta-configuration.
Meta-config can contain the following top level properties to define one
or more ConfigSources:
type - specifies the built-in configuration type
(environment-variables, system-properties, directory, file, url,
prefixed, classpath) or the custom
config types of the ConfigSource being defined.
class - fully-qualified class name of one of:
ConfigSource implementation,Config.Builder implementation with a build() method
that returns a ConfigSource instance.type or
class but not both. If the meta-config specifies both the config
system ignores the class 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 or class source
declaration using properties. See
AbstractParsableConfigSource.Builder.init(Config) for the
available properties for types other than system-properties and
environment-variables (which do not support properties
settings).
| 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) |
keytype or classproperties
|
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-in polling-strategy types
regular and watch. See PollingStrategy for
details about all supported properties and custom implementation support.
It also shows the built-in retry-policy type repeat. See
RetryPolicy for more information.
class
instead of type in the meta-configuration. The referenced class
must implement either ConfigSource or Config.Builder. If
the custom implementation extends
AbstractParsableConfigSource.Builder then the config system will
invoke its init method passing a Config 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.
META-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 custom ConfigSource or a
builder for a custom ConfigSource.
For example, the module helidon-config-git includes the resource
META-INF/resources/meta-config-sources.properties containing
git = io.helidon.config.git.GitConfigSourceBuilderThis defines the new source type
git which can then be
referenced from meta-configuration this way:
{
type = "git"
properties {
path = "application.conf"
directory = "/app-config/"
}
}
metaConfig - meta-configuration used to initialize the
ConfigSourceConfigSource described by metaConfigMissingValueException - 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 typeConfigSources.load(Supplier[]),
ConfigSources.load(Config)default ConfigSource get()
get in interface Supplier<ConfigSource>default void init(ConfigContext context)
ConfigContext.
The method is executed during Config bootstrapping by Config.Builder.
context - a config contextCopyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.