【问题标题】:Defining an array in play's config file在 play 的配置文件中定义一个数组
【发布时间】:2014-03-06 11:28:06
【问题描述】:

我没有找到有关该主题的任何信息。有没有办法在标准播放配置文件app.config 中定义一个数组,其值如下?

application.secret="Gk<9kCgMu@A62eyfcJ;YZ2nFnA;4324/gfdg]afdsfds"
application.langs="en"
application.global=common.Global

【问题讨论】:

    标签: scala playframework config playframework-2.2


    【解决方案1】:

    是的,这是可能的,并在Play configuration chapter 中进行了描述。

    一般来说,您正在寻找的是:

    my.setting="[value1,value2,value3]"
    

    在您的代码中,您可以像这样访问它:

    Play.current.configuration.getStringList("my.setting") //returns an Option[java.util.List[String]]
    

    你也可以使用getLongListgetBooleanList等等。

    【讨论】:

    • 我们可以在配置文件本身中进行列表连接吗?
    【解决方案2】:

    我在搜索“play framework config array”时找到了这个答案。

    对于 Play 2.7,列表的正确语法是:

    my.setting=["value1","value2","value3"]
    

    否则你会得到一个异常

    com.typesafe.config.ConfigException$WrongType: application.conf @ file:/xxxxx/application.conf: 12:  my.setting has type STRING rather than LIST
    

    希望这对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 2016-07-12
      • 2019-07-18
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多