尝试使用Typesafe配置库获取列表

时间:2016-07-23 16:01:29

标签: scala typesafe

我尝试根据此示例从配置中获取列表:How to get a list with the Typesafe config library

但是,我得到以下例外:

Exception in thread "main" com.typesafe.config.ConfigException$WrongType: application.properties @ file:/xxx/application.properties: configYYY has type STRING rather than LIST
    at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:159)
    at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:170)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:184)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:189)
    at com.typesafe.config.impl.SimpleConfig.getList(SimpleConfig.java:252)
    at com.typesafe.config.impl.SimpleConfig.getHomogeneousUnwrappedList(SimpleConfig.java:323)
    at com.typesafe.config.impl.SimpleConfig.getStringList(SimpleConfig.java:381)

如何从typesafe获取列表?以下是我的测试代码:

class Test extends FlatSpec {
  "Test" should "be about to get list" in {

    val configFactory = ConfigFactory.load();
    var disabledExtension = configFactory.getStringList("disabledExtension");
    assert(2==disabledExtension.size());
    assert(disabledExtension.get(0).equals("SH"));
    assert(disabledExtension.get(1).equals("ST"));
  }
}

在我的application.properties下面:

disabledExtension = ["SH", "ST"]

1 个答案:

答案 0 :(得分:1)

application.properties必须是application.conf

“ *。properties”文件中的任何属性都将被读取为字符串。