Typesafe config: Load additional config from path external to packaged scala application

南楼画角 提交于 2021-02-05 12:59:08

问题


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:

val hdfsConfig = ConfigFactory.load("my_path/hdfs.conf")

回答1:


I think what you want is:

val myCfg =  ConfigFactory.parseFile(new File("my_path/hdfs.conf"))



回答2:


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 yourFile is a java.io.File Documentation reference here




回答3:


val config = ConfigFactory.load("pathtoFile/FileName.propertes") 

works, too.



来源:https://stackoverflow.com/questions/18195527/typesafe-config-load-additional-config-from-path-external-to-packaged-scala-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!