16.1新建一个IDemo1的接口类;
packagecom.eduask.mypack1;
publicinterfaceIDemo1 {
publicvoidtestDemo1();
}
16.2新建一个Demo1的类,实现IDemo1接口;
packagecom.eduask.mypack1;
//Demo1实现IDemo1接口;
publicclassDemo1implementsIDemo1 {
privateintid;
privateString name;
privateString pwd;
publicintgetId() {
returnid;
}
publicvoidsetId(intid) {
this.id = id;
}
publicString getName() {
returnname;
}
publicvoidsetName(String name) {
this.name = name;
}
publicString getPwd() {
returnpwd;
}
publicvoidsetPwd(String pwd) {
this.pwd = pwd;
}
@Override
publicvoidtestDemo1() {
//TODOAuto-generated method stub
System.out.println("id="+id+" name="+name+" pwd="+pwd);
}
}
16.3新建一个TestDemo1的测试类;
packagecom.eduask.mypack1;
importorg.springframework.context.support.ClassPathXmlApplicationContext;
publicclassTestDemo1 {
publicstaticvoidmain(String[] args) {
ClassPathXmlApplicationContext cx=newClassPathXmlApplicationContext("entityXmlmypack1/demo1.xml");
Demo1 demo1=(Demo1) cx.getBean("demo1");
demo1.setId(1);
demo1.setName("tom");
demo1.setPwd("123456");
demo1.testDemo1();
}
}
16.3 新建一个demo1.xml的配置文件;
"1.0"encoding="UTF-8"?>
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-2.5.xsd"
>
16.5 程序运行如下:
id=1 name=tom pwd=123456