5.1 编写一个Demo3的实体类;
package com.eduask.entity;
public class Demo3 {
private int id;
private String name;
private String pwd;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public Demo3(){
System.out.println("这是Demo3的构造方法");
}
public void testDemo3(){
System.out.println("Demo3 [id=" + id + ", name=" + name + ", pwd=" + pwd + "]");

}
}
5.2编写一个TestDemo3测试类;
package com.eduask.entity;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDemo3 {
public static void main(String[] args) {
ClassPathXmlApplicationContext cx = new ClassPathXmlApplicationContext("demo3.xml");
Demo3 demo3 = (Demo3) cx.getBean("Demo3");
demo3.testDemo3();
}
}
5.3 编写一个demo3.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="Demo3" class="com.eduask.entity.Demo3" scope="prototype">
<property name="id" value="001"/>
<property name="name" value="tom"/>
<property name="pwd" value="123456"/>
</bean>
</beans>