unknown configuration format: hocon (supported formats are: [json, raw, properties]

梦想的初衷 提交于 2020-02-04 23:19:12

问题


I am trying to use the Hocon format for configuration in Vertx. I have also added the maven dependency for it.

<dependency>
            <groupId>com.typesafe</groupId>
            <artifactId>config</artifactId>
            <version>1.3.3</version>
        </dependency>

        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-config-hocon</artifactId>
            <version>3.5.1</version>
        </dependency>

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.


回答1:


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)



来源:https://stackoverflow.com/questions/50610406/unknown-configuration-format-hocon-supported-formats-are-json-raw-properti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!