WEB开发网
开发学院软件开发Java Spring原理自我实践之IOC的模拟实现 阅读

Spring原理自我实践之IOC的模拟实现

 2009-09-18 00:00:00 来源:WEB开发网   
核心提示: Class_4:测试类 Java代码packagetest;importcom.java.interfaces.Car;importcom.java.interfaces.Wheel;importcom.java.mySpring.MyIOC;publicclassTestMyIOC{publi

Class_4:测试类

Java代码   

package test; 
 
import com.java.interfaces.Car; 
import com.java.interfaces.Wheel; 
import com.java.mySpring.MyIOC; 
 
public class TestMyIOC { 
 public static void main(String args[]) throws Exception { 
 MyIOC myIOC = new MyIOC(); 
 Car car1 = (Car) myIOC.getBean("carImpl"); 
 car1.setColor("green"); 
 Wheel wheel = (Wheel) myIOC.getBean("wheelImpl"); 
  
 System.out.println("对象的信息:"+car1.getId() + " " + car1.getColor() + " " 
  + car1.getWheel().getId() + " " + car1.getWheel().getSize()); 
 System.out.println("wheel.hashCode()" + wheel.hashCode()); 
 System.out.println("结束"); 
 } 
} 

配置文件:

Xml代码   

<?xml version="1.0" encoding="UTF-8"?> 
<beans> 
 <bean id="carImpl" class="com.java.beans.CarImpl"> 
 <property name="id" value="001" /> 
 <property name="color" value="red" /> 
 <property name="wheel" ref="wheelImpl"/> 
 </bean> 
 <bean id="wheelImpl" class="com.java.beans.WheelImpl"> 
 <property name="id" value="001" /> 
 <property name="size" value="50cm" /> 
 </bean> 
</beans> 

上一页  1 2 3 4 5  下一页

Tags:Spring 原理 自我

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接