3

我有一个这样的属性文件

com.country.<COUNTRY>=<values comma seperated>

例如:

com.country.UK=100,200
com.country.US=10,20

现在将来可以添加许多其他国家/地区条目我可以Map<String,List<Integer>>通过 propertyPlaceHolder 将这些值输入到 spring 应用程序上下文 xml 中吗?

4

1 回答 1

1

你可以使用 spring util: 不要忘记导入 scheme,使用 util:map 和 util:list 来构造你想要的任何结构。可以使用 ref-ids 作为值:

<beans  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util-2.5.xsd">

<util:map id="map1" map-class="java.util.HashMap">
    <entry key="smthgkey" value="smthvalue"/>
</util:map>

<util:list id="list1" list-class="java.util.ArrayList">
    <value>val1</value>
</util:list>

另一种方法是创建具有必要结构的bean,但我从未使用过这种方式。您可以在此处找到示例:如何在 Spring 中定义 List bean?

于 2013-10-09T07:03:59.163 回答