Announcement Announcement Module
Collapse
No announcement yet.
Simple merge of util:map Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple merge of util:map

    I'm trying to get a map merged, and it's not working, and I'm about to put my fist through my monitor .... so I'm asking for some help before I do that.

    I have two maps.

    Code:
    	<bean id="commonData" class="A">
    		<property name="map">
    		    <util:map>
    		    	<entry key="1" value="1" />
    		    </util:map>
    		</property>
    	</bean>
    	<bean id="data" class="A" parent="commonData">
    		<property name="map">
    		    <util:map merge="true">
    		    	<entry key="2" value="2" />
    		    </util:map>
    		</property>
    	</bean>
    When the final object A gets injected into the object that's using it, the map only contains the child entries, not both. I'm sure I'm missing something obvious here, or just don't understand merging at all .... any help would be wonderful.

  • #2
    The merge option works fine for me when using the DTD style for configuration. When i use the XML schema style I get the same error you found.

    Comment


    • #3
      Your configuration looks for me perfectly correct.
      If it really does not work, you have perfectly valid reason to file bug in JIRA.

      Regards,

      Oleksandr

      Originally posted by nstoddar View Post
      I'm trying to get a map merged, and it's not working, and I'm about to put my fist through my monitor .... so I'm asking for some help before I do that.

      I have two maps.

      Code:
      	<bean id="commonData" class="A">
      		<property name="map">
      		    <util:map>
      		    	<entry key="1" value="1" />
      		    </util:map>
      		</property>
      	</bean>
      	<bean id="data" class="A" parent="commonData">
      		<property name="map">
      		    <util:map merge="true">
      		    	<entry key="2" value="2" />
      		    </util:map>
      		</property>
      	</bean>
      When the final object A gets injected into the object that's using it, the map only contains the child entries, not both. I'm sure I'm missing something obvious here, or just don't understand merging at all .... any help would be wonderful.

      Comment


      • #4
        You appear to be misusing <util:map>. The <util:map> tag is intended for creating a named bean that is a Map (it's a shortcut for MapFactoryBean). If you just want to create a map as a property value of some other bean, just use <map> instead, like so:

        Code:
        	<bean id="commonData" class="A">
        		<property name="map">
        		    <map>
        		    	<entry key="1" value="1" />
        		    </map>
        		</property>
        	</bean>
        	<bean id="data" class="A" parent="commonData">
        		<property name="map">
        		    <map merge="true">
        		    	<entry key="2" value="2" />
        		    </map>
        		</property>
        	</bean>
        Last edited by kcalcagno; May 9th, 2008, 01:54 PM. Reason: spelling

        Comment


        • #5
          util:map merging

          I don't want to beat this to death, but it sure would be handy to be able to merge instances of util:map, as in
          Code:
                   <util:map id="map1">
          	     <entry key="1" value="1" />
                  </util:map>
          
          	<bean id="commonData" class="A">
          		<property name="map" ref="map1"/>
          	</bean>
          
                  <util:map id="map2" parent="map1" merge="true">
          		<entry key="2" value="2" />
                  </util:map>
          
          
          	<bean id="data" class="A" parent="commonData">
          		<property name="map" ref="map2"/>
          	</bean>
          It would also be really nice to be able to mix-and-match between the two styles.
          Oh, yes...and a pony, too, please!

          Comment


          • #6
            It works

            Put the <map merge="true" in the overwriting bean instead of at the parent level. It will work fine.

            Comment

            Working...
            X