第四讲:4.1 Spring 注入参数-基本类型
1,复制Spring40102 改名为Spring40203,创建JUnit文件夹,eclipse添加JUnit包(右击项目->build path ->configure build path -> Add Libiary ->JUnit),删除com.cruise.factory多余包, 删除com.cruise.test包下的多余类Test2,在 com.cruise.test包下,新建JUnit Test Case文件,命名为 T 类,
2,修改 beans.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.xsd">
<bean id="people1" class="com.cruise.entity.People">
<property name="id" value="1">property>
<property name="name" value="张三">property>
<property name="age" value="11">property>
bean>
beans>
3,修改Test类,运行-测试
package com.cruise.test;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.cruise.entity.People;
public class T {
private ClassPathXmlApplicationContext CPXAC=null;
@Before
public void setUp() throws Exception {
CPXAC= new ClassPathXmlApplicationContext("beans.xml");
}
@Test
public void test1() {
People people1 = (People)CPXAC.getBean("people1");
System.out.println(people1);
}
}