类型安全配置:从外部路径加载附加配置到打包的 scala 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18195527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Typesafe config: Load additional config from path external to packaged scala application
提问by RAbraham
My scala application will be packaged into a jar. When I run my app, it needs to read an additional config file stored externally to my app jar. I am looking for functionality similar to the Typesafe Config library but other solutions are welcome too ! Is there a way to do something like below:
我的 scala 应用程序将被打包成一个 jar。当我运行我的应用程序时,它需要读取存储在我的应用程序 jar 外部的附加配置文件。我正在寻找类似于 Typesafe Config 库的功能,但也欢迎其他解决方案!有没有办法做类似下面的事情:
val hdfsConfig = ConfigFactory.load("my_path/hdfs.conf")
回答by cmbaxter
I think what you want is:
我想你想要的是:
val myCfg = ConfigFactory.parseFile(new File("my_path/hdfs.conf"))
回答by tcat
If your external configuration is to add to or override configuration parameters from standard locations, you can do the following:
如果您的外部配置要从标准位置添加或覆盖配置参数,您可以执行以下操作:
val baseConfig = ConfigFactory.load()
val config = ConfigFactory.parseFile(yourFile).withFallback(baseConfig)
where yourFileis a java.io.FileDocumentation reference here
这里yourFile的java.io.File文档参考在哪里
回答by Suresh Chaganti
val config = ConfigFactory.load("pathtoFile/FileName.propertes")
works, too.
也有效。

