标签:
如果 Bean 的属性是个集合,则可以使用 <list/>、<set/>、<map/> 和 <props/> 元素向 List、Set、Map 和 Properties 类型的属性注入值。
注入集合值的配置示例:
<bean id="moreComplexObject" class="example.ComplexObject"> <!-- results in a setAdminEmails(java.util.Properties) call --> <property name="adminEmails"> <props> <prop key="administrator">administrator@example.org</prop> <prop key="support">support@example.org</prop> <prop key="development">development@example.org</prop> </props> </property> <!-- results in a setSomeList(java.util.List) call --> <property name="someList"> <list> <value>a list element followed by a reference</value> <ref bean="myDataSource" /> </list> </property> <!-- results in a setSomeMap(java.util.Map) call --> <property name="someMap"> <map> <entry key="an entry" value="just some string" /> <entry key="a ref" value-ref="myDataSource" /> </map> </property> <!-- results in a setSomeSet(java.util.Set) call --> <property name="someSet"> <set> <value>just some string</value> <ref bean="myDataSource" /> </set> </property> </bean>
Spring(3.2.3) - Beans(5): 集合属性的注入
标签:
原文地址:http://www.cnblogs.com/huey/p/4507149.html