spring 配置测试
1、java文件Student。
package com;
/**
* Student entity. @author MyEclipse Persistence Tools
*/
public class Student implements java.io.Serializable {
// Fields
private Integer stuId;
private String stuName;
private Integer stuAge;
private String stuSex;
private String stuTel;
private String stuAddress;
private Birth bir;
// Constructors
public Birth getBir() {
return bir;
}
public void setBir(Birth bir) {
this.bir = bir;
}
/** default constructor */
public Student() {
}
/** full constructor */
public Student(String stuName, Integer stuAge, String stuSex,
String stuTel, String stuAddress) {
this.stuName = stuName;
this.stuAge = stuAge;
this.stuSex = stuSex;
this.stuTel = stuTel;
this.stuAddress = stuAddress;
}
// Property accessors
public Integer getStuId() {
return this.stuId;
}
public void setStuId(Integer stuId) {
this.stuId = stuId;
}
public String getStuName() {
return this.stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public Integer getStuAge() {
return this.stuAge;
}
public void setStuAge(Integer stuAge) {
this.stuAge = stuAge;
}
public String getStuSex() {
return this.stuSex;
}
public void setStuSex(String stuSex) {
this.stuSex = stuSex;
}
public String getStuTel() {
return this.stuTel;
}
public void setStuTel(String stuTel) {
this.stuTel = stuTel;
}
public String getStuAddress() {
return this.stuAddress;
}
public void setStuAddress(String stuAddress) {
this.stuAddress = stuAddress;
}
@Override
public String toString() {
return "Student [bir=" + bir + ", stuAddress=" + stuAddress
+ ", stuAge=" + stuAge + ", stuId=" + stuId + ", stuName="
+ stuName + ", stuSex=" + stuSex + ", stuTel=" + stuTel + "]";
}
}
2、java文件Birth。
package com;
public class Birth {
private int y;
private int m;
private int d;
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getM() {
return m;
}
public void setM(int m) {
this.m = m;
}
public int getD() {
return d;
}
public void setD(int d) {
this.d = d;
}
public Birth() {
}
public Birth(int y,int m,int d){
super();
this.y=y;
this.m=m;
this.d=d;
}
public String toString() {
return "Birth [d=" + d + ", m=" + m + ", y=" + y + "]";
}
}
3。java文件Run。
package com;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;
public class Run {
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
Birth bir=(Birth)context.getBean("birth");
Student student=(Student)context.getBean("student");
System.out.println(student);
}
}
4、配置文件。
<bean id="birth" value="1987"></property>
<property name="m" value="11"></property>
<property name="d" value="22"></property>
</bean>
<bean id="student" value="刘趁阳"></property>
<property name="stuAge" value="24"></property>
<property name="stuId" value="20070711"></property>
<property name="bir" ref="birth"></property>
</bean>
5、执行Run文件,就可以了,spring的实质就是在spring的容器中生成java类的实例。