简体   繁体   English

从外部属性文件动态填充 application.conf

[英]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.我想动态填写 application.conf 值。

These values should be read from the correct properties file (${env}.props.properties).这些值应该从正确的属性文件 (${env}.props.properties) 中读取。 The correct properties file depends on the property env which is given with a run or build command (Denv=xxx).正确的属性文件取决于通过运行或构建命令 (Denv=xxx) 给出的属性 env。

application.conf应用程序配置文件
key=${my.property.value.read.from.props.properties.file}键=${my.property.value.read.from.props.properties.file}
key2=...键 2=...

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.您可以通过在运行应用程序时指定标志-Dconfig.resource=your.file.properties来告诉 Typesafe Config 加载不同的配置文件。 If the config file is not a bundled resource you can use -Dconfig.file=/path/to/your.file.properties instead.如果配置文件不是捆绑资源,您可以使用-Dconfig.file=/path/to/your.file.properties代替。 (You can also specify an URL with -Dconfig.url ; see https://github.com/typesafehub/config#user-content-standard-behavior for more info) (您也可以使用-Dconfig.url指定 URL;有关更多信息,请参阅https://github.com/typesafehub/config#user-content-standard-behavior

Doing this will skip loading application.conf altogether so remember to set Play!-specific properties in your own properties-file.这样做将完全跳过加载 application.conf,因此请记住在您自己的属性文件中设置 Play! 特定的属性。

You can try Typesafe ConfigFactory.invalidateCaches to invalid config entries.您可以尝试使用 Typesafe ConfigFactory.invalidateCaches来设置无效的配置条目。 As api doc says;正如 api 文档所说; 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).首先进行更改,然后调用上面的 api,然后调用load() (一种解决方案是让调度程序每 x 间隔调用一次)。 Disclaimer - I haven't tried it myself https://lightbend.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#invalidateCaches--免责声明 - 我自己没有尝试过https://lightbend.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#invalidateCaches--

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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