简体   繁体   中英

Play dynamically fill in application.conf from external properties file

My project setup looks as follows:

项目结构

I would like to dynamically fill in application.conf values.

These values should be read from the correct properties file (${env}.props.properties). The correct properties file depends on the property env which is given with a run or build command (Denv=xxx).

application.conf
key=${my.property.value.read.from.props.properties.file}
key2=...

Thanks in advance!

You can tell Typesafe Config to load a different config file altogether by specifying flag -Dconfig.resource=your.file.properties as you run your application. If the config file is not a bundled resource you can use -Dconfig.file=/path/to/your.file.properties instead. (You can also specify an URL with -Dconfig.url ; see https://github.com/typesafehub/config#user-content-standard-behavior for more info)

Doing this will skip loading application.conf altogether so remember to set Play!-specific properties in your own properties-file.

You can try Typesafe ConfigFactory.invalidateCaches to invalid config entries. As api doc says; first make the changes then call above api, followed by load() (one solution would be to have a scheduler that calls it every x interval). Disclaimer - I haven't tried it myself https://lightbend.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#invalidateCaches--

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