繁体   English   中英

引用类型安全配置中的值

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM