How to inject a Map in java springs?

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

<util:list id="list1">
    <value>foo@bar.com</value>
    <value>foo1@bar.com</value>
</util:list>

<util:list id="list2">
    <value>foo2@bar.com</value>
    <value>foo3@bar.com</value>
</util:list>

<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" />
    ...
</util:map>

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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)