Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Framework: Map - Value Referencing to another Map

Tags:

java

spring

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?

like image 257
Milli Zeloski Avatar asked Jan 22 '23 13:01

Milli Zeloski


1 Answers

Firstly, the XML is not well-formed, it should be:

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

Also, according to your definition, the someMapRef map bean can only contain values of type java.util.HashMap, but you're trying to set a value for key 0 of SOME VALUE, which is a String. It can contain Strings, or hashMaps, but not both.

like image 162
skaffman Avatar answered Jan 26 '23 00:01

skaffman