Stu.java
package com.yan;
import java.util.List;
public class Stu {
private String username;
private Integer xuehao;
private List
public Stu(String username,Integer xuehao,List
super();
this.username = username;
this.xuehao = xuehao;
this.list = list;
}
public Stu() {
super();
}
public void setUsername(String username) {
this.username = username;
}
public void setXuehao(Integer xuehao) {
this.xuehao = xuehao;
}
public void setList(List
this.list = list;
}
public String toString() {
return "User {学生=" + username + ", 学号=" + xuehao + ", list=" + list + "}";
}
}
GraStu.java
package com.yan;
import com.yan.Stu;
public class GraStu {
private String teacher;
private Stu m;
private Stu n;
public void setStu1(Stu n){
this.n = n;
}
public void setStu(Stu m){
this.m = m;
}
public String teacher() {
return "teacher";
}
public GraStu(String teacher) {
super();
this.teacher = teacher;
}
public GraStu() {
super();
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public void setN(Stu n) { this.n = n;}
public void setM(Stu m) { this.m = m;}
public String toString1() {
return "User {" + n + " 老师:" + teacher + "}";
}
public String toString() {
return "User {" + m + " 老师:" + teacher + "}";
}
}
abc.xml
"1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
Text.java
package com.yan;
import org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
@SuppressWarnings("unused")
public class Text {
public static void main(String[] args) {
String xmlPath = "com/yan/abc.xml";
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext (xmlPath);
System.out.println(applicationContext.getBean("stu1"));
System.out.println(applicationContext.getBean("stu2"));
System.out.println(applicationContext.getBean("userGrad"));
System.out.println(applicationContext.getBean("useGrad"));
}
}