我正在尝试使用typesafe config
阅读以下配置文件common = {
jdbcDriver = "com.mysql.jdbc.Driver"
slickDriver = "slick.driver.MySQLDriver"
port = 3306
db = "foo"
user = "bar"
password = "baz"
}
source = ${common} {server = "remoteserver"}
target = ${common} {server = "localserver"}
当我尝试使用此代码阅读我的配置时
val conf = ConfigFactory.parseFile(new File("src/main/resources/application.conf"))
val username = conf.getString("source.user")
我收到错误
com.typesafe.config.ConfigException$NotResolved: source.user has not been resolved, you need to call Config#resolve(), see API docs for Config#resolve()
如果我把所有内容都放在里面,我就不会有任何错误。来源"或"目标"标签。只有在我尝试使用" common"
时才会出错答案 0 :(得分:3)
我自己解决了。
ConfigFactory.parseFile(new File("src/main/resources/application.conf")).resolve()