<?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans 6 http://www.springframework.org/schema/beans/spring-beans.xsd 7 http://www.springframework.org/schema/context 8 http://www.springframework.org/schema/context/spring-context.xsd"> 9 10 <bean id="department" class="com.LHB.collection.Department"> 11 <property name="name" value="财务部门" /> 12 <!-- 给数组注入值 --> 13 <property name="empName"> 14 <list> 15 <value>小米</value> 16 <value>小明</value> 17 <value>小四</value> 18 </list> 19 </property> 20 21 <!-- 给list注入值 可以有相同的多个对象 --> 22 <property name="empList"> 23 <list> 24 <ref bean="emp1" /> 25 <ref bean="emp2"/> 26 </list> 27 </property> 28 <!-- 给set注入值 不能有相同的对象 --> 29 <property name="empSets"> 30 <set> 31 <ref bean="emp1" /> 32 <ref bean="emp2"/> 33 </set> 34 </property> 35 36 <!-- 给map注入值 只要map中的key值不一样就可以装配value --> 37 <property name="empMap"> 38 <map> 39 <entry key="1" value-ref="emp1" /> 40 <entry key="2" value-ref="emp2" /> 41 </map> 42 </property> 43 44 <!-- 给属性集合配置 --> 45 <property name="pp"> 46 <props> 47 <prop key="pp1">hello</prop> 48 <prop key="pp2">world</prop> 49 </props> 50 </property> 51 </bean> 52 <bean id="emp1" class="com.LHB.collection.Employee"> 53 <property name="name"> 54 <value>北京</value> 55 </property> 56 </bean> 57 <bean id="emp2" class="com.LHB.collection.Employee"> 58 <property name="name"> 59 <value>天津</value> 60 </property> 61 </bean> 62 63 </beans>