Config Sources
Creating MicroProfile Config Sources for Manual Setup of Config
You can use the following methods to create MicroProfile Config Sources to
manually set up the Config from
org.eclipse.microprofile.config.spi.ConfigProviderResolver#getBuilder() on
io.helidon.config.mp.MpConfigSources class:
| Method | Description |
|---|---|
systemProperties() | System properties config source. |
environmentVariables() | Environment variables config source. |
create( | Loads a properties file from file system. To load the properties file from file system with custom name, use create(String, java.nio.file.Path) |
create( | Creates an in-memory source from map. To create an in-memory source from map with custom name, use create(String, java.util.Map). |
create( | Creates an in-memory source from properties. To create an in-memory source from properties with custom name, use create( |
Create Custom Map MicroProfile Config Source
You can create MicroProfile Config Source from a map.
Create MicroProfile Config Source based on Environment Variables and Custom Map:
Create YAML MicroProfile Config Source
You can create YAML MicroProfile Config Source from a path or a URL. When you
create a MicroProfile instance from the builder, the YamlMpConfigSource allows
you to create a custom Config Source and register it with the builder.
Create YamlMPConfigSource from a path:
ConfigProviderResolver.instance().getBuilder()
.withSources(YamlMpConfigSource.create(path))
.build();
Creating Custom Config Sources
Custom Config Sources are loaded using the Java Service Loader pattern, by
implementing either org.eclipse.microprofile.config.spi.ConfigSource, or
org.eclipse.microprofile.config.spi.ConfigSourceProvider SPI and registering
it as a service (Using META-INF/services/${class-name} file when using
classpath, or using the provides statement in module-info.java when using
module path).
The interface org.eclipse.microprofile.config.spi.ConfigSource requires
implementation of the following methods:
String getName()Map<String, String> getProperties()String getValue(String key)getOrdinal()
Example of a Custom Config Source
Creating MicroProfile Config Sources from meta-config
Instead of directly specifying the configuration sources in your code, you can use meta-configuration in a file that declares the configuration sources, and their attributes as mentioned in MicroProfile Config.
When used, the MicroProfile Config uses configuration sources and flags configured in the meta configuration file.
If a file named mp-meta-config.yaml, or mp-meta-config.properties is in the
current directory or on the classpath, and there is no explicit setup of
configuration in the code, the configuration will be loaded from the
meta-config file. The location of the file can be overridden using system
property io.helidon.config.mp.meta-config, or environment variable
HELIDON_MP_META_CONFIG.
meta-config.*, to avoid conflicting with
Helidon SE Meta Configuration.Example of a YAML meta configuration file:
Important Note: To enable support for HOCON and JSON types, add the
following dependency to your project’s pom.xml.
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-hocon-mp</artifactId>
</dependency>
Extending Meta-Config to Create a Custom Config Source Type
Helidon meta-config by default supports the following types:
environment-variables, system-properties, properties, yaml, hocon and json.
Users can also extend meta-config to create a custom config source type by
loading it using the Java Service Loader pattern. This is achieved by
implementing io.helidon.config.mp.spi.MpMetaConfigProvider SPI and registering
it as a service (Using META-INF/services/${class-name} file when using
classpath, or using the provides statement in module-info.java when using
module path).
The interface io.helidon.config.mp.spi.MpMetaConfigProvider requires
implementation of the following methods:
Set<String> supportedTypes()List<? extends ConfigSource> create(String type, Config metaConfig, String profile);
Example of a Meta-Config Custom Type
Creating MicroProfile Config Source from Helidon SE Config Source
To use the Helidon SE features in Helidon MP, create MicroProfile Config Source from Helidon SE Config Source. The Config Source is immutable regardless of configured polling strategy or change watchers.
Creating MicroProfile Config Source from Helidon SE Config Instance
To use advanced Helidon SE features in Helidon MP, create MicroProfile Config
Source from Helidon SE Config. The Config Source is mutable if the config uses
either polling strategy and change watchers, or polling strategy or change
watchers. The latest config version is queried each time
org.eclipse.microprofile.config.spi.ConfigSource#getValue(String) is called.