[英]Spring context.xml and Set.contains()
Spring: In my context.xml, I have: 春季:在我的context.xml中,我有:
<util:set id="someIDs"
set-class="java.util.HashSet"
value-type="java.lang.String">
<value>"W000000001"</value>
<value>"W000000003"</value>
<value>"W000000009"</value>
</util:set>
In my Java bean, the implementation is: 在我的Java bean中,实现是:
private Set<String> someSet =
ComUtilities.uncheckedCast(getApplicationContext()
.getBean("someIDs"));
boolean found = someSet.contains("W000000009");
After the execution of avobe code block, found is very weirdly false! 执行avobe代码块后,发现很奇怪的是假! How come? 怎么会? Any suggestion/idea? 有什么建议/想法吗? Thanks a bunch. 谢谢你
Off the top of my head - I'm pretty sure that Spring doesn't require double quotes for String data. 让我烦恼的是-我很确定Spring不需要String数据使用双引号。 So it's probably inserting those strings into the map with actual double-quote characters at the start and the end. 因此,可能会将这些字符串插入到映射中,在开头和结尾处使用实际的双引号字符。
Try checking 尝试检查
boolean found = someSet.contains("\"W000000009\"");
to see if this is the case. 看是否是这种情况。
I think it's because you've quoted the values in the Spring config and then the contains check is looking for an unquoted string. 我认为这是因为您已经在Spring配置中引用了值,然后contains检查正在寻找未引用的字符串。 Replace you spring config with this: 用以下命令替换spring配置:
<util:set id="someIDs"
set-class="java.util.HashSet"
value-type="java.lang.String">
<value>W000000001</value>
<value>W000000003</value>
<value>W000000009</value>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.