依存性注入:Beanオブジェクトの作成は、コンテナーによって異なります。Beanオブジェクトのすべてのプロパティは、コンテナによって注入されます。
コンストラクターインジェクション、セットインジェクション、エクステンションインジェクションに分けることができます
環境構築:
エンティティクラス:
Beans.xml
テストクラス:
@Test
public void mytest(){
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("beans.xml");
Student student = (Student) context.getBean("student");
System.out.println(student.toString());
}
試験結果:
Student{name='秦江', address=Address{address='南京'},
books=[红楼梦, 西游记, 水浒传, 三国演义],
hobbies=[睡觉, 吃饭, 听歌],
card={身份证=1001, 校园卡=1002},
games=[王者荣耀, 吃鸡],
info={学号=123, 专业=计算机, 性别=男}}