主目录中的Typesafe配置文件

4 scala home-directory typesafe-config

从我所读到的,类安全配置库读取类路径或系统变量.这对我来说效果不好,因为在命令行上传递许多参数是不可行的,我不希望我们的devops团队只是为了更改设置而重建jar.他们对设置环境变量的负载也不太满意.

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

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

Sas*_*erg 5

除了指定一个acommand行参数:之外-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)
Run Code Online (Sandbox Code Playgroud)