Dependency Injection: The creation of bean objects depends on the container. All properties in the bean object are injected by the container.
It can be divided into constructor injection, Set injection, and extension injection
Environment build:
Entity class:
beans.xml
Test class:
@Test
public void mytest(){
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("beans.xml");
Student student = (Student) context.getBean("student");
System.out.println(student.toString());
}
Test Results:
Student{name='秦江', address=Address{address='南京'},
books=[红楼梦, 西游记, 水浒传, 三国演义],
hobbies=[睡觉, 吃饭, 听歌],
card={身份证=1001, 校园卡=1002},
games=[王者荣耀, 吃鸡],
info={学号=123, 专业=计算机, 性别=男}}