Question

I'm trying to implement this Java data structure in Spring (which I am new to):

Map<String, List<String>> 

I tried the below (and variants of it), but am getting the following exception:

Caused by: org.xml.sax.SAXParseException; lineNumber: XX; columnNumber: YY; cvc-complex-type.2.4.d: Invalid content was found starting with element 'util:list'. No child element is expected at this point.

Can someone tell me the mistake I am making? I need to be able to build out the above mentioned "Map" data structure with literal Keys (String) and List of values. I included twp complete sample "entries" (which are not working) just to show the fill-in pattern that I'm seeking to create.

    <bean .... >
      ...
    <property name="monitoredObjects">
        <util:map map-class="java.util.HashMap">
            <entry key="java.lang:type=GarbageCollector,name=ConcurrentMarkSweep">
                <value>
                    <util:list>
                        <value>HeapMemoryUsage</value>
                        <value>NonHeapMemoryUsage</value>
                    </util:list>
                </value>
            </entry>

            <entry key="java.lang:type=FOO,name=BAR">
                <value>
                    <util:list>
                        <value>YADA-YADA</value>
                        <value>BLAH-BLAH</value>
                    </util:list>
                </value>
            </entry>
        </util:map>
    </property>
      ...
    </bean>

Thank you! =:)

Was it helpful?

Solution

I tinkered some more and got it to work by removing "value" elements that enclosed the util:list elements. In other words, like this:

<bean .... >
    ...
   <property name="monitoredObjects">
       <util:map map-class="java.util.HashMap">

           <entry key="java.lang:type=GarbageCollector,name=ConcurrentMarkSweep">
                   <util:list>
                       <value>HeapMemoryUsage</value>
                       <value>NonHeapMemoryUsage</value>
                   </util:list>
           </entry>

           <entry key="java.lang:type=FOO,name=BAR">
                   <util:list>
                       <value>YADA-YADA</value>
                       <value>BLAH-BLAH</value>
                   </util:list>
           </entry>

       </util:map>
   </property>
   ...
</bean>

Thanks as always for looking!

OTHER TIPS

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> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top