packagecom.test;importcom.charon.enty.Acount;importcom.charon.enty.Student;importorg.junit.Before;importorg.junit.Test;importorg.springframework.context.ApplicationContext;importorg.springframework.context.support.ClassPathXmlApplicationContext;importjava.util.HashMap;/*** @Description TODO
* @Author Charon <1819248612@qq.com>
* @create 2020-11-06-0:45
* @Version 1.0.0*/
public classStudentTest {
ApplicationContext applicationContext;
@Beforepublic voidbefore(){//定义Spring配置文件的位置
String xmlPath = "ApplicationContext.xml";//初始化Spring配置文件,加载配置文件
applicationContext = newClassPathXmlApplicationContext(xmlPath);
}/*** 测试通过有参构造给bean赋值*/@Testpublic voidtest(){
Student student= (Student) applicationContext.getBean("student1");
System.out.println(student.getStuName());
}/*** 测试通过有参构造给bean赋值*/@Testpublic voidtest1(){
Student student= (Student) applicationContext.getBean("student2");
student.setStuName("李四");
System.out.println(student.getStuName());
}/*** Spring 自动匹配合适的构造器;*/@Testpublic voidtest3(){
Student student3= (Student)applicationContext.getBean("student3");
System.out.println(student3.getStuName());
System.out.println(student3.getStuAge());
System.out.println(student3.getStuDept());
}/*** 测试引用外部bean给对象赋值*/@Testpublic voidtest4(){
Student student= (Student) applicationContext.getBean("student4");
System.out.println(student.getStuName());
System.out.println(student.getAcount().getIdCard());
}/*** 测试给List集合赋值结果*/@Testpublic voidtest5(){
Acount acount= (Acount)applicationContext.getBean("list1");for (int i = 0; i < acount.getHobby().size(); i++) {
System.out.println(acount.getHobby().get(i));
}
}/*** 测试给Map集合赋值结果*/@Testpublic voidtest6(){
Acount acount= (Acount)applicationContext.getBean("account3");
HashMap hashMap =acount.getHashMap();
System.out.println(hashMap.get("name"));
System.out.println(hashMap.get("age"));
}
}