spring 4.0 起步2 集合注入配置

来源:互联网 发布:淘宝天猫仓储外包 编辑:程序博客网 时间:2024/05/10 00:09

首先创建一个集合类:

package ioc.xml;import java.util.List;import java.util.Map;import java.util.Set;public class FruitCollection {private Map fruitmap;private List fruitlist;private Set fruitset;public Map getFruitmap() {return fruitmap;}public void setFruitmap(Map fruitmap) {this.fruitmap = fruitmap;}public List getFruitlist() {return fruitlist;}public void setFruitlist(List fruitlist) {this.fruitlist = fruitlist;}public Set getFruitset() {return fruitset;}public void setFruitset(Set fruitset) {this.fruitset = fruitset;}}
然后在xml文件中配置

 <!-- 集合属性注入 <bean id="collection"  class="ioc.FruitCollection"><property name="fruitlist"><list>
<!-- 配置普通属性--><value>string1</value>
<pre name="code" class="html"><!-- 引用其他的bean-->
<ref bean="apple1"/><value>this is blind dog</value></list></property>

<property name="fruitmap"><map>
<pre name="code" class="html"><!-- 配置普通属性-->
<entry key="key1" value="apple1"></entry><entry key="key2" value="apple2"></entry><entry key="key3" value="apple3"></entry>
<pre name="code" class="html"><!-- 引用其他的bean-->
<entry key="key4" value-ref="apple1"></entry></map></property>
<property name="fruitset"><set>
<pre name="code" class="html"><!-- 配置普通属性-->
<value>apple1</value>
<pre name="code" class="html"><!-- 引用其他的bean-->
<ref bean="pear1"/><value>pear1</value></set></property></bean>-->



0 0