我正在尝试使用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”时才会出现错误

最佳答案

我自己解决了。

ConfigFactory.parseFile(new File("src/main/resources/application.conf")).resolve()

关于scala - com.typesafe.config.ConfigException $ NotResolved : has not been resolved,,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41528547/

10-12 17:35