spring简单配置

 1 <?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" xmlns:p="http://www.springframework.org/schema/p"

 4     xmlns:context="http://www.springframework.org/schema/context"

 5     xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"

 6     xsi:schemaLocation="

 7             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

 8             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd

 9             http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd

10             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

11     <bean id="department" class="com.ruby.collection.Department">

12         <property name="name" value="财政部"></property>

13         <!-- 给数组注入值 -->

14         <property name="empName">

15             <list>

16                 <value>小明</value>

17                 <value>小李</value>

18                 <value>小张</value>

19             </list>

20         </property>

21         

22         <!-- 给list注入值 -->

23         <property name="empList">

24             <list>

25                 <ref bean="emp1"></ref>

26                 <ref bean="emp2"></ref>

27             </list>

28         </property>

29         

30         <!-- 给Set注入值 -->

31         <property name="empSet">

32             <set>

33                 <ref bean="emp1"></ref>

34                 <ref bean="emp2"></ref>

35             </set>

36         </property>

37         

38         <!-- 给Map注入值 -->

39         <property name="empMap">

40             <map>

41                 <entry key="1" value-ref="emp1"></entry>

42                 <entry key="2" value-ref="emp2"></entry>

43             </map>

44         </property>

45     </bean>

46     

47     <bean id="emp1" class="com.ruby.collection.Employee">

48         <property name="name" value="ruby"></property>

49         <property name="id" value="1"></property>

50     </bean>

51     <bean id="emp2" class="com.ruby.collection.Employee">

52         <property name="name" value="Lua"></property>

53         <property name="id" value="2"></property>

54     </bean>

55 </beans>

 

你可能感兴趣的:(spring)