【发布时间】:2016-11-27 09:01:38
【问题描述】:
我尝试根据此示例从配置中获取列表: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"]
【问题讨论】:
-
什么是配置,你正在尝试什么代码?
-
该错误表示您在此键处没有列表,而是一个字符串。例如。如果您有
a, b之类的内容,则应改为["a", "b"]。 -
是的,我已经在使用 ["a", "b"] 了,但是它仍然报这个错误,让我先尝试一些更简单的方法
-
您找到解决方案了吗?
-
不,我自己解析它,disabledExtension = SH|ST