Spring控制反转与依赖注入(IOC、DI)
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- 到入xml文件的约束 -->
3 <beans xmlns="http://www.springframework.org/schema/beans"
4 xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://www.springframework.org/schema/beans
6 http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
7 <!-- 1 实例化Dao对象 id:完成对象的引用 class:指定需要创建的对象对应的类的完全限定名 -->
8 <bean id="usersDao" class="org.guangsoft.dao.impl.UsersDaoImpl">
9 </bean>
10 <!-- 2实例化service -->
11 <bean id="usersService" class="org.guangsoft.service.impl.UsersServiceImpl">
12 <!-- property:完成对象属性的注入(赋值) value:如果是简单的类型使用value(String,基本类型对应的包装类型) ref:完成对应的引用 -->
13 <property name="usersDao" ref="usersDao"></property>
14 </bean>
15 <!-- 3实例化Action对象 -->
16 <bean id="usersAction" class="org.guangsoft.action.UsersAction">
17 <property name="usersService" ref="usersService"></property>
18 </bean>
19 </beans>
来源: http://www.bubuko.com/infodetail-1855790.html