How to provide
configurations to an application
This section shows how to provide configurations to an application in different environments via different configuration sources.
Supported Configuration Sources
The specification demands the following configuration sources to be supported by any implementation and processed in the given order:
- System Properties
- Environment variables
- META-INF/microprofile-config.properties
Configurations provided by a configuration source of a higher ordinal will overlay configurations provided by a configuration source of a lower ordinal. Custom configuration sources can be implemented as well and will be discovered via SPI. For instance, the Smallrye implementation provides a DirectoryConfigSource which processes configurations from files located in a configured directory (nested directories are not supported), in which the filename represents the configuration name and the file content the configuration value. This is very useful in cases where the application runs in a Linux Container in the cloud.
How to provide configuration for Wildfly/EAP
Configurations for an application running on a Wildfly/EAP can be provided as system properties defined in the standalone.xml, environment variables defined in the host system or configurations provided by the Smallrye subsystem.
System properties in standalone.xml:
<system-properties>
<property name="conax.request.dir" value="/tmp/cmnt/req"/>
</system-properties>
Properties in the subsystem in standalone.xml:
<subsystem xmlns="urn:wildfly:microprofile-config-smallrye:1.0">
<config-source name="props">
<property name="prop1" value="foo"/>
<property name="prop2" value="bar"/>
</config-source>
</subsystem>
Directory configuration in the subsystem in standalone.xml:
<subsystem xmlns="urn:wildfly:microprofile-config-smallrye:1.0">
<config-source name="file-props">
<dir path="/etc/config/numbers-app"/>
</config-source>
</subsystem>
Configuring directory source via the JBos-CLI:
/subsystem=microprofile-config-smallrye/config-source=file-props \
:add(dir={path=/etc/config/numbers-app})
Configuring properties via the JBos-CLI:
/subsystem=microprofile-config-smallrye/config-source=props \
:add(properties={"prop1" = "foo", "prop2" = "bar"})
How to provide configurations for Thorntail
Configurations for an application running on Thorntail might be provided via system properties defined during startup, via environment variables defined by the host Linux Container or via configurations defined in YAML files within the application (supports stages). The YAML files might also be put outside the application and provided via startup arguments.
There are multiple ways to configure Thorntail via YAML files which are explained in the following list.
- src/main/resources/microprofile-config.properties
The configuration file which is enforced by the specification to be supported by any implementation
- src/main/resources/project-defaults.yaml
This file should contain the default configurations applicable for all stages
- src/main/resources/project-stages.yaml
This file should contain configurations for multiple stages separated via ‘– – -’, which indicates that this YAML file contains actually multiple YAML files. The stages can be selected via startup arguments or a system property like this:
// Activates all stages contained in project-stages.yaml
java -jar app-thorntail.jar -Slocal,test
// Activates one single stage in project-stages.yaml
java -Dthorntail.project.stage=test -jar app-thorntail.jar
- src/main/resources/project-test.yaml
Configuration file for the test stage. The configuration file can be activated via a startup argument like, for example:
// Activates all stages contained in project-stages.yaml
java -jar app-thorntail.jar -Stest
- /some_dir/external-config.yaml
Contains the configuration outside the application which can be provided via startup arguments:
java -jar app-thorntail.jar -s /some_dir/external-config.yaml
The cited example shows a YAML file project-stages.yaml which contains configurations for the stages ‘local’, ‘test’ and ‘cloud’.
Staged MicroProfile-Config configuration:
# Configurations for all stages
thorntail:
microprofile:
config:
config-sources:
STATIC_CONFIG:
properties:
info: "The application info..."
— — -
project:
stage: local
thorntail:
microprofile:
config:
config-sources:
LOCAL_CONFIG:
properties:
prop: "local-prop"
— — -
project:
stage: test
thorntail:
microprofile:
config:
config-sources:
TEST_CONFIG:
properties:
prop: "test-prop"
— — -
project:
stage: cloud
thorntail:
microprofile:
config:
config-sources:
CLOUD_CONFIG:
Dir: “/config/app”
How to provide configurations for Quarkus
Configurations for an application running with Quarkus can be provided via system properties defined during startup, environment variables defined by the hosting Linux Container or via configurations defined in a properties file within the application.
There are multiple ways to configure Quarkus which are explained in the following list.
- src/main/resources/microprofile-config.properties
The configuration file which is enforced by the specification to be supported by any implementation
- src/main/resources/application.properties
The Quarkus specific configuration file
- Via system properties during startup
java -Dproperty=value -jar app-quarkus.jar
I am not familiar with Quarkus yet, and just used it to illustrate that a JEE application can run oin multiple application runtimes.