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>
Sourceof configuration.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static ConfigSourcecreate(Config metaConfig)Initializes aConfigSourcefrom meta-configuration.default ConfigSourceget()default voidinit(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 aConfigSourcefrom 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 theConfigSourcebeing defined.class- fully-qualified class name of one of:- a
ConfigSourceimplementation, - a
Config.Builderimplementation with abuild()method that returns aConfigSourceinstance.
- a
typeorclassbut not both. If the meta-config specifies both the config system ignores theclassinformation.As the config system loads configuration it uses mappers to convert the raw data into Java types. See
ConfigMapperProviderfor details about mapping.The meta-config can modify a
typeorclasssource declaration usingproperties. SeeAbstractParsableConfigSource.Builder.init(Config)for the available properties for types other thansystem-propertiesandenvironment-variables(which do not supportpropertiessettings).
Example configuration in HOCON format:Predefined Configuration Source Types Source Type Further Information Mandatory Properties system-propertiesConfigSources.systemProperties()none environment-variablesConfigSources.environmentVariables()none classpathConfigSources.classpath(String)resourcefileConfigSources.file(String)pathdirectoryConfigSources.directory(String)pathurlConfigSources.url(URL)urlprefixedConfigSources.prefixed(String, Supplier)key
typeorclass
propertiessources = [ { 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-strategytypesregularandwatch. SeePollingStrategyfor details about all supported properties and custom implementation support. It also shows the built-inretry-policytyperepeat. SeeRetryPolicyfor more information.Custom Sources and Source Types
Custom Configuration Sources
The application can define a custom config source usingclassinstead oftypein the meta-configuration. The referenced class must implement eitherConfigSourceorConfig.Builder. If the custom implementation extendsAbstractParsableConfigSource.Builderthen the config system will invoke itsinitmethod passing aConfigobject 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.propertieson 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 customConfigSourceor a builder for a customConfigSource.For example, the module
helidon-config-gitincludes the resourceMETA-INF/resources/meta-config-sources.propertiescontaininggit = io.helidon.config.git.GitConfigSourceBuilder
This defines the new source typegitwhich 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:
ConfigSourcedescribed 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:
getin interfaceSupplier<ConfigSource>
-
init
default void init(ConfigContext context)
Initialize the config source with aConfigContext.The method is executed during
Configbootstrapping byConfig.Builder.- Parameters:
context- a config context
-
-