开发者

Spring loading set with Integer values

I'm using Spring to load a Set containg integers:

<util:set id="ModifiableTags" set-class="java.util.HashSet">
        <value>44</value>
        <value>38</value>
        <value>111</value>
        <value>110</value>
        <value>40</value>
</开发者_开发百科util:set>

However, when I get the bean it always turns into a Set of String.

Set<Integer> tags = (HashSet<Integer>)clientAppContext.getBean("ModifiableTags");
for(Integer tag : tags) { // EXCEPTION as String can't be converted to Integer!
}

How do I force Spring to load the values as Integer? Thanks.


Try:

<util:set set-class="java.util.HashSet" value-type="java.lang.Integer">
    <!-- ... -->
</util:set>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜