Spring Frame: Map - Meaning Link to another map

I have a map declaration:

<!-- SOME MAP --> <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String" > <entry key="0" value="SOME VALUE" /> <entry key="1" value="SOME VALUE 2" /> <entry key="default" value="SOME VALUE 3" /> </util:map> <!-- SOME MAP REFERENCE --> <util:map id="someMapRef" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.util.HashMap" > <entry key="0" value ref = "someMap" /> <entry key="default" value="SOME VALUE" /> </util:map> 

What is wrong with that? Any suggestion?

+4
source share
3 answers

Firstly, the XML is not correctly formed, it should be:

 <entry key="0" value-ref="someMap"/> 

Also, according to your definition, someMapRef bean map can only contain values โ€‹โ€‹of type java.util.HashMap , but you are trying to set the value for the key 0 of SOME VALUE , which is String. It may contain strings or hashMaps, but not both.

+9
source

Invalid XML:

 <entry key="0" value ref = "someMap" /> 

remove "value"

0
source

I think it should work as follows:

 <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String"> <entry key="0" value="SOME VALUE" /> <entry key="1" value="SOME VALUE 2" /> <entry key="default" value="SOME VALUE 3" /> </util:map> <!-- type: Map<String, Map<String, String>> --> <util:map id="someMapRef" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.util.Map"> <entry key="0" value-ref="someMap" /> <!-- value-ref not "value ref" --> <!-- This is the map constructed above --> <entry key="SOME_VALUE"> <map> <!-- and here is another map --> <entry key="SOME_OTHER_KEY1" value="SOME_OTHER_VALUE1" /> <entry key="SOME_OTHER_KEY2" value="SOME_OTHER_VALUE2" /> <entry key="SOME_OTHER_KEY3" value="SOME_OTHER_VALUE3" /> </map> </entry> </util:map> 
0
source

All Articles