hocon配置文件_未知的配置格式:hocon(支持的格式为:[json,原始,属性]

时间:2025-03-08 08:10:42

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

config

1.3.3

vertx-config-hocon

3.5.1

The code compiles fine in eclipse.

Vertx vertx = ();

DeploymentOptions options = new DeploymentOptions();

ConfigStoreOptions store = new ConfigStoreOptions().setType("file").setFormat("hocon").setConfig(new JsonObject().put("path", ("configPath")));

ConfigRetriever retriever = (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:

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

I have also checked in the jar file. And I don't find the expected .

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/ file). Can you check the content of this file in your final jar? To work, it must contain the 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/#ServicesResourceTransformer for details. The Maven Plugin does that automatically (/reactiverse/vertx-maven-plugin)