Hocon Configuration Format
The Hocon Configuration Format extends the Vert.x Configuration Retriever and provides the support for the HOCON format.
It supports includes, json, properties, macros…
Using the Hocon Configuration Format
To use the Hocon Configuration Format, add the following dependency to the dependencies section of your build descriptor:
-
Maven (in your
pom.xml):
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-config-hocon</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-config</artifactId>
<version>4.5.0</version>
</dependency>
-
Gradle (in your
build.gradlefile):
compile 'io.vertx:vertx-config:4.5.0'
compile 'io.vertx:vertx-config-hocon:4.5.0'
Configuring the store to use HOCON
Once added to your classpath or dependencies, you need to configure the
ConfigRetriever to use this format:
ConfigStoreOptions store = new ConfigStoreOptions()
.setType("file")
.setFormat("hocon")
.setConfig(new JsonObject()
.put("path", "my-config.conf")
);
ConfigRetriever retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(store));
You just need to set format to hocon.
Override configuration using system environment variables
Hocon supports system environment variable overrides using keys with CONFIG_FORCE_ prefix. You can use this feature by specifying hocon.env.override to true in the configuration:
ConfigStoreOptions store = new ConfigStoreOptions()
.setType("file")
.setFormat("hocon")
.setConfig(new JsonObject()
.put("hocon.env.override", true)
.put("path", "my-config.conf")
);
ConfigRetriever retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(store));