IOC(控制反转:InverseofControl ) ,又称作 依赖注入,是一种重要的面向对象编程的法则来削减计算机程序 的耦合问题,也是轻量级的 Spring 框架的核心。
第二节:spring ioc 实例讲解
参考源码
<?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.xsd"> <!-- 声明zhangsan实例 --> <bean id="zhangsan" class="com.fx.service.ZhangSan"></bean> <!-- 声明lisi实例 --> <bean id="lisi" class="com.fx.service.Lisi"></bean> <!-- 将lisi注入到JavaWork中 --> <bean id="javaWork" class="com.fx.service.JavaWork"> <property name="tester" ref="lisi"></property> </bean> </beans>