From fc4818ba9ead7f42484a25b5390696a826b05edd Mon Sep 17 00:00:00 2001 From: qinyingjie Date: Sat, 12 Nov 2022 20:30:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B5=8B=E8=AF=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/kwan/spring5/Book.java | 13 +++++++++++- src/main/resources/spring10.xml | 26 ++++++++++++++++++++++++ src/test/java/Spring_08_BookTest.java | 22 ++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/spring10.xml create mode 100644 src/test/java/Spring_08_BookTest.java diff --git a/src/main/java/com/kwan/spring5/Book.java b/src/main/java/com/kwan/spring5/Book.java index c8bb53f..8533a5f 100644 --- a/src/main/java/com/kwan/spring5/Book.java +++ b/src/main/java/com/kwan/spring5/Book.java @@ -1,5 +1,7 @@ package com.kwan.spring5; +import java.util.List; + /** * 书籍 set方法注入属性 * @@ -9,13 +11,17 @@ package com.kwan.spring5; */ public class Book { /** - * 姓名 + * 名称 */ private String bname; /** * 作者 */ private String bauthor; + /** + * 书名 + */ + private List list; /** * 创建属性对应的set方法 @@ -28,11 +34,16 @@ public class Book { this.bauthor = bauthor; } + public void setList(List list) { + this.list = list; + } + @Override public String toString() { return "Book{" + "bname='" + bname + '\'' + ", bauthor='" + bauthor + '\'' + + ", list=" + list + '}'; } } diff --git a/src/main/resources/spring10.xml b/src/main/resources/spring10.xml new file mode 100644 index 0000000..6cc3d2d --- /dev/null +++ b/src/main/resources/spring10.xml @@ -0,0 +1,26 @@ + + + + + + + + 易筋经 + 九阴真经 + 九阳神功 + + + + + + + \ No newline at end of file diff --git a/src/test/java/Spring_08_BookTest.java b/src/test/java/Spring_08_BookTest.java new file mode 100644 index 0000000..8608ec6 --- /dev/null +++ b/src/test/java/Spring_08_BookTest.java @@ -0,0 +1,22 @@ +import com.kwan.spring5.Book; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * 测试ioc注入 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2022/11/12 18:43 + */ +public class Spring_08_BookTest { + + @Test + public void test1() { + ApplicationContext ctx = + new ClassPathXmlApplicationContext("spring10.xml"); + Book book = (Book) ctx.getBean("book"); + System.out.println(book); + } +} -- GitLab