一般我们知道在property属性里面定义一个无id的map是比较容易的, 但是如何将map定义一个单独的bean, 以便重用, google了一下, [url=http://forum.springsource.org/archive/index.php/t-32356.html]这里[/url]给出了说明, 不过有些问题, 没有value那个节点, 不知道是否spring版本的问题, 修改之后, 备注一下.
还用另外一种形式:
<bean id="SymbolMap" class="java.util.HashMap">
<constructor-arg>
<map>
<entry>
<key><value><![CDATA[us;djia]]></value></key>
<value><![CDATA[us&dji]]></value>
</entry>
</map>
</constructor-arg>
</bean>
还用另外一种形式:
<bean id="emails" class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="pechorin" value="pechorin@hero.org"/>
<entry key="raskolnikov" value="raskolnikov@slums.org"/>
<entry key="stavrogin" value="stavrogin@gov.org"/>
<entry key="porfiry" value="porfiry@gov.org"/>
</map>
</property>
</bean>
<bean id="fieldMap" class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="title" value-ref="obj"></entry>
<entry key="reserve_price" value-ref="double"></entry>
<entry key="auction_status" value-ref="obj"></entry>
<entry key="quantity" value-ref="obj"></entry>
<entry key="options" value-ref="obj"></entry>
<entry key="spu_id" value-ref="obj"></entry>
<entry key="sold_quantity" value-ref="obj"></entry>
<entry key="features" value-ref="obj"></entry>
<entry key="category" value-ref="obj"></entry>
<entry key="user_id" value-ref="obj"></entry>
<entry key="auction_id" value-ref="obj"></entry>
<entry key="gmt_modified" value-ref="date"></entry>
<entry key="pict_url" value-ref="obj"></entry>
<entry key="sync_version" value-ref="obj"></entry>
</map>
</property>
</bean>
<bean id="date" class="java.lang.Class" factory-method="forName">
<constructor-arg value="java.util.Date"/>
</bean>
<bean id="double" class="java.lang.Class" factory-method="forName">
<constructor-arg value="java.lang.Double"/>
</bean>
<bean id="obj" class="java.lang.Class" factory-method="forName">
<constructor-arg value="java.lang.Object"/>
</bean>