views:

821

answers:

3

Spring: In my context.xml, I have:

<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:

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! How come? Any suggestion/idea? Thanks a bunch.

+3  A: 

Off the top of my head - I'm pretty sure that Spring doesn't require double quotes for String data. 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.

Andrzej Doyle
+1  A: 

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. Replace you spring config with this:

<util:set id="someIDs" 
  set-class="java.util.HashSet"
      value-type="java.lang.String">
             <value>W000000001</value>
             <value>W000000003</value>
             <value>W000000009</value>

GaryF
A: 

It was beyond my imagination that after I specified the value type, the behavior could be like that.. Thank you very much guys for the help.