开发者

Spring loading set with Integer values

开发者 https://www.devze.com 2023-03-22 14:01 出处:网络
I\'m using Spring to load a Set containg integers: <util:set id=\"ModifiableTags\" set-class=\"java.util.HashSet\">

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

精彩评论

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