applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="person" class="cn.itcast.spring0909.di.xml.set.Person">
<!--
property就是代表属性
在spring中基本类型(包装类型和String)都可以用value来赋值
引用类型用ref赋值
-->
<property name="pid" value="5"></property>
<property name="pname" value="王二麻子"></property>
<property name="student" ref="student">
</property>
<property name="lists">
<list>
<value>list1</value>
<value>list2</value>
<ref bean="student"/>
</list>
</property>
<property name="sets">
<set>
<value>set1</value>
<value>set2</value>
<ref bean="student"/>
</set>
</property>
<property name="map">
<map>
<entry key="map1">
<value>map1</value>
</entry>
<entry key="map2">
<value>map2</value>
</entry>
<entry key="map3">
<ref bean="student"/>
</entry>
</map>
</property>
<property name="properties">
<props>
<prop key="prop1">
prop1
</prop>
</props>
</property>
</bean>
<bean id="student" class="cn.itcast.spring0909.di.xml.set.Student"></bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="person" class="cn.itcast.spring0909.di.xml.constructor.Person">
<!--
构造函数的参数
index 第几个参数,下标从0开始
type 参数的类型
ref 如果类型是引用类型,赋值
value 如果类型是基本类型,赋值
说明:
只能指定一个构造函数
-->
<constructor-arg index="0" type="java.lang.String" value="干露露"></constructor-arg>
<constructor-arg index="1" ref="student"></constructor-arg>
</bean>
<bean id="student" class="cn.itcast.spring0909.di.xml.constructor.Student"></bean>
</beans>
面向接口的操作
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 把documentManager,worddocument,exceldocument,pdfdocument -->
<bean id="documentManager" class="cn.itcast.spring0909.document.spring.DocumentManager">
<!--
document是一个接口
-->
<property name="document">
<!--
通过ref给接口赋值
-->
<ref bean="wordDocument"/>
</property>
</bean>
<bean id="wordDocument" class="cn.itcast.spring0909.document.spring.WordDocument"></bean>
<bean id="excelDocument" class="cn.itcast.spring0909.document.spring.ExcelDocument"></bean>
<bean id="pdfDocument" class="cn.itcast.spring0909.document.spring.PDFDocument"></bean>
</beans>
mvc
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="personAction" class="cn.itcast.spring0909.mvc.spring.PersonAction">
<property name="personService">
<ref bean="personSerivce" />
</property>
</bean>
<bean id="personSerivce" class="cn.itcast.spring0909.mvc.spring.PersonServiceImpl">
<property name="personDao">
<ref bean="personDao" />
</property>
</bean>
<bean id="personDao" class="cn.itcast.spring0909.mvc.spring.PersonDaoImpl"></bean>
</beans>