Aravind Aravind - 5 months ago 23
Java Question

How to inject a Map<String, List> in java springs?

How to inject a Map in java spring framework?
If possible please provide some sample code.

Is the following legal?

<property name="testMap">


Define a Map like this first inside your applicationContext.xml:

   <util:list id="list1">

   <util:list id="list2">

   <util:map id="emailMap" value-type="java.util.List">
      <!-- Map between String key and List -->
      <entry key="entry1" value-ref="list1" />
      <entry key="entry2" value-ref="list2" />

Then use this Map in any bean of yours like this:

   <bean id="myBean" class="com.sample.beans">
      <property name="emailMap" ref="emailMap" />