vert-x3 / vertx-config

Vert.x Configuration Service
Apache License 2.0
54 stars 64 forks source link

Java Properties configuration in Spring Boot style #56

Closed eutkin closed 6 years ago

eutkin commented 6 years ago

The standard implementation of the configuration through properties does not display structures. I.e:

server.port=8080
server.host=http://localhost
multivalue=1,2,3

It will be transformed

{  
   "server.port":8080,
   "server.host":"http://localhost",
   "multivalue":"1,2,3"
}

But there are cases when it is important for us to correctly display the structure, and not the "flat" properties:

{  
   "server":{  
      "port":8080,
      "host":"http://localhost"
   },
   "multivalue":[  
      1,
      2,
      3
   ]
}

This StoreProcessor allows you to convert .properties to a json object in the same way that Spring Boot converts .properties to java objects.

Example:

retriever = ConfigRetriever.create(vertx,
      new ConfigRetrieverOptions()
        .addStore(
          new ConfigStoreOptions()
            .setType("file")
            .setFormat("properties")
            .setConfig(
              new JsonObject()
                .put("hierarchical", true)
                .put("path", "src/test/resources/file/jsonable.properties")))
    );

retriever.getConfig(ar -> {
      JsonObject config = ar.result();
      int port = config.getJsonObject("server").getInteger("port");
    });
cescoffier commented 6 years ago

Looks great, can you drop a line in the documentation?

eutkin commented 6 years ago

What documentation?

eutkin commented 6 years ago

anyone?

cescoffier commented 6 years ago

Sorry missed your message. The documentation for this PR need to be written in src/main/asciidoc/index.adoc. It should just explain how it works and give a simple example.

cescoffier commented 6 years ago

Can you also rename the PR? master is a bit vague.

cescoffier commented 6 years ago

@eutkin did you sign the Eclipse CLA?

eutkin commented 6 years ago

nope

cescoffier commented 6 years ago

@eutkin You can sign it there: https://www.eclipse.org/legal/ECA.php.

eutkin commented 6 years ago

done

cescoffier commented 6 years ago

The CI complains about not finding the implementation java.util.ServiceConfigurationError: io.vertx.config.spi.ConfigProcessor: Provider io.vertx.config.impl.spi.HierarchicalPropertiesStoreProcessor not found.

Can you investigate?

eutkin commented 6 years ago

done

cescoffier commented 6 years ago

And merged!

Thanks again for your hard work!

eutkin commented 6 years ago

thank you