简体   繁体   中英

How to use vert.x config read json files?

I want to use vert.x config modules to read json files.

Because do not like using

-conf src/main/conf/my-application-conf.json

Sometimes we don't use complex operation commands when we need change a configuration.

I found a way to get this, please see github

Do you have more ways? Can we use vert.x config modules?

Except json, some type files need to write in conf. Such as yaml.

Please tell me how to use vert.x config modules to get that infomation and how to use as a jsonObject.

Thanks!

if i understand correctly, it looks like you're looking for an alternative approach to accessing config files by means other than specifying the -conf program argument and subsequently accessing via AbstractVerticle.config() .

the example you linked to seemed like a good idiomatic approach - is there something about it that doesn't suit your needs?

another way of doing this, assuming your configs are packaged in your application's jar, is to leverage the ClassLoader to return a stream to those resources, like so:

getClass().getClassLoader().getResourceAsStream("/my-application-conf.json")

while this relies on core Java APIs without requiring extra modules like Vert.x Config, it would introduce a bit of synchronous/blocking code into your codebase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM