简体   繁体   English

主目录中的Typesafe配置文件

[英]Typesafe config file in home directory

From what I have read the typesafe config library reads from the classpath or system variables. 从我所读到的,类安全配置库读取类路径或系统变量。 This doesn't work very well for me because passing many arguments on the command line is not feasible and I don't want our devops team to have to rebuild the jars just to change a setting. 这对我来说效果不好,因为在命令行上传递许多参数是不可行的,我不希望我们的devops团队只是为了更改设置而重建jar。 They're also not too happy about setting loads of environment variables. 他们对设置环境变量的负载也不太满意。

Is is possible to specify an external file that is not on the classpath, similar to the way Spring works? 是否可以指定不在类路径上的外部文件,类似于Spring的工作方式?

Ideally I would it to look in the ~/.ourapp.conf file first, then look for environment variables and finally fallback to application.conf and reference.conf. 理想情况下,我首先查看〜/ .ourapp.conf文件,然后查找环境变量,最后回退到application.conf和reference.conf。

Apart form specifiying a acommand line parameter: -Dconfig.file= , you could do it in the code with something like this: 除了指定一个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)

您可以在命令行上根据https://www.playframework.com/documentation/2.0/ProductionConfiguration指定-Dconfig.file =〜/ .ourapp.conf

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

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