MicroProfile Config

Helidon’s MicroProfile Config, an implementation of Eclipse MicroProfile Config, enables you to configure your applications using MicroProfile’s config configuration sources and APIs.

Maven Coordinates

To enable MicroProfile Config either add a dependency on the helidon-microprofile bundle or add the following dependency to your project’s pom.xml (see Managing Dependencies).

        <dependency>
            <groupId>io.helidon.microprofile.config</groupId>
            <artifactId>helidon-microprofile-config</artifactId>
        </dependency>
Copied

About MicroProfile Config

Helidon MicroProfile Config is an implementation of Eclipse MicroProfile Config. You can configure your applications using MicroProfile’s config configuration sources and APIs. You can also extend the configuration using MicroProfile SPI to add custom ConfigSource and Converter.

MicroProfile Config Features

MicroProfile Config uses ConfigSource SPI to load configuration data, either from default configuration sources such file META-INF/microprofile-config.properties, environment variables, and system properties; or from custom ConfigSource located by Java Service Loader.

The data is then available through MicroProfile Config APIs to be injected into CDI Beans, or to be obtained using a Config instance programmatically.

MicroProfile Config provides typed access to configuration values, using built-in converters, and Converter implementations located by Java Service Loader.

Using MicroProfile Config API

You can use MicroProfile Config API to get configuration properties by using ConfigProvider.getConfig() or injecting configuration values with @ConfigProperty.

Using ConfigProvider.getConfig()
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
config.getOptionalValue("app.greeting", String.class).orElse("Hello");
Copied
Injecting configured properties into a constructor
@Inject
public GreetingProvider(@ConfigProperty(name = "app.greeting", defaultValue = "Hello") String message) {
    this.message = message
}
Copied

MicroProfile Config Config Sources

The example below shows how the MicroProfile configuration file microprofile-config.properties can be used to modify the server listen port property.

// Application properties. This is the default greeting
app.greeting=Hello

// Microprofile server properties
server.port=8080
server.host=0.0.0.0
Copied

MicroProfile Config Profiles

MicroProfile Config supports a concept of configuration profiles. You can define a profile using the configuration property mp.config.profile (when using default configuration, this can be defined as a system property, environment variable or as a property in microprofile-config.properties). When a profile is defined, additional config source is loaded (microprofile-config-profile.properties) and properties from profile have precedence over default properties. Profile properties can be defined using %profile prefix, such as %dev.server.port.

Helidon MicroProfile Config Features

Helidon MicroProfile Config offers the following features on top of the specification:

  • References
    You can use ${reference} to reference another configuration key in a key value. This allows to configure a single key to be reused in multiple other keys.

Example
uri: "http://localhost:8080"
service-1: "${uri}/service1"
service-2: "${uri}/service2"
Copied
  • Change support
    Polling (or change watching) for file based config sources (not classpath based).

To enable polling for a config source created using meta configuration (see below), or using MpConfigSources.create(Path), or YamlMpConfigSource.create(Path), use the following properties:

PropertyDescription
helidon.config.polling.enabledTo enable polling file for changes, uses timestamp to identify a change.
helidon.config.polling.durationPolling period duration, defaults to 10 seconds ('PT10S`)
See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence)
helidon.config.watcher.enabledTo enable watching file for changes using the Java WatchService.
See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/WatchService.html
  • Encryption
    You can encrypt secrets using a master password and store them in a configuration file. The config encryption filter in MicroProfile Config is enabled by default. For more information, see Configuration Secrets.

Example of encrypted secrets
# Password encrypted using a master password
client_secret=${GCM=mYRkg+4Q4hua1kvpCCI2hg==}
# Password encrypted using public key (there are length limits when using RSA)
client_secret=${RSA=mYRkg+4Q4hua1kvpCCI2hg==}
# Password in clear text, can be used in development
# The system needs to be configured to accept clear text
client_secret=${CLEAR=known_password}
Copied
  • Meta Configuration
    You can configure the Config using Helidon MP Config meta configuration feature. The meta-config allows configuration of config sources and other configuration options, including addition of discovered sources and converters.

This is a Helidon specific feature available since version 2.3.0. See Microprofile Config Sources for detailed information.

For backward compatibility, we will support usage of Helidon SE meta-configuration until version 3.0.0. Using this approach causes behavior that is not compatible with MicroProfile Config specification.

Guides

MP Config Guide

Step-by-step guide about using MicroProfile Config in your Helidon MP application.

Additional Information