[英]Referencing to values in typesafe config
我有一個配置文件:
app {
system {
action-type = "REST"
}
}
roles = [${app.system.action-type} "notifier"]
我希望角色具有值[RESTnotifier],但是這種方法給了我一個例外。 有什么建議么?
com.typesafe.config.ConfigException$NotResolved: need to Config#resolve() each config before using it, see the API docs for Config#resolve()
如果要在Config
中使用替換,則需要在Config
實例上顯式調用resolve
。 一個簡單的示例顯示如下:
import com.typesafe.config.ConfigFactory
import collection.JavaConversions._
object ConfigExample extends App{
val cfgString = """
app {
system {
action-type = "REST"
}
}
roles = [${app.system.action-type}"notifier"]
"""
val cfg = ConfigFactory.parseString(cfgString).resolve()
println(cfg.getStringList("roles").toList)
}
注意顯式調用resolve
。 那應該解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.