diff --git a/src/main/java/com/kwan/spring5/Book.java b/src/main/java/com/kwan/spring5/Book.java index c8bb53ffef21132bdb19b181ef6b531cc2c2c4fa..8533a5f3fad9c2779b6f5c0b82758ab41fba4b0c 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 0000000000000000000000000000000000000000..6cc3d2d7e8057260c7fae0b1433e4467d1ec1f0a --- /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 0000000000000000000000000000000000000000..8608ec6396c888ffc921702253eb40802925a792 --- /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); + } +}