主目录中的类型安全配置文件

Typesafe config file in home directory

据我所知,类型安全配置库从类路径或系统变量中读取。这对我来说不是很好,因为在命令行上传递许多参数是不可行的,我不希望我们的 devops 团队不得不重建 jars 只是为了更改设置。他们也不喜欢设置大量环境变量。

是否可以指定一个不在类路径中的外部文件,类似于 Spring 的工作方式?

理想情况下,我会先查看 ~/.ourapp.conf 文件,然后查找环境变量,最后回退到 application.conf 和 reference.conf.

您可以根据 https://www.playframework.com/documentation/2.0/ProductionConfiguration

在命令行中指定 -Dconfig.file=~/.ourapp.conf

除了指定命令行参数:-Dconfig.file=,您还可以在代码中使用如下内容:

val defaults = ConfigFactory.load()
val file = new File("~/path/custom.config")
// I'm not sure what you mean with environment variables, 
// but you could read environment variables into a map and then use 
val env = ConfigFactory.parseMap(envMap)
val settings = ConfigFactory.parseFile(file).withFallBack(env).withFallBack(defaults)