I am trying to use the Hocon format for configuration in Vertx. I have also added the maven dependency for it.
com.typesafe
config
1.3.3
io.vertx
vertx-config-hocon
3.5.1
The code compiles fine in eclipse.
Vertx vertx = Vertx.vertx();
DeploymentOptions options = new DeploymentOptions();
ConfigStoreOptions store = new ConfigStoreOptions().setType("file").setFormat("hocon").setConfig(new JsonObject().put("path", System.getProperty("configPath")));
ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
However, when I run the binary and passing a hocon configuration file as a command line argument, I am getting the following unknown configuration exception:
java.lang.IllegalArgumentException: unknown configuration format: hocon (supported formats are: [json, raw, properties]
I have also checked io.vertx.config.spi.ConfigProcessor in the jar file. And I don't find the expected io.vertx.config.hocon.HoconProcessor.
Am I missing some build configuration in POM file? Is there any important thing to be included in the POM file to resolve this issue.
解决方案
The vertx-config formats are configured using a SPI file (META-INF/services/io.vertx.config.spi.ConfigProcessor file). Can you check the content of this file in your final jar? To work, it must contain the io.vertx.config.hocon.HoconProcessor line. As you are also depending on vertx-config (also containing this file), you need to configure the Maven Shader plugin to combine the different files into one. Check https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ServicesResourceTransformer for details. The Vert.x Maven Plugin does that automatically (https://github.com/reactiverse/vertx-maven-plugin)