顾名思义set注入必须要有set方法。
基本类型的注入、引用类型注入、List注入、Set注入、Map注入、Properties注入
1 public class person { 2 private car c; 3 private pay p; 4 private List list; 5 private Set set; 6 private Map map; 7 private Properties prop; 8 9 public List getList() {10 return list;11 }12 public void setList(List list) {13 this.list = list;14 }15 public Set getSet() {16 return set;17 }18 public void setSet(Set set) {19 this.set = set;20 }21 public Map getMap() {22 return map;23 }24 public void setMap(Map map) {25 this.map = map;26 }27 public Properties getProp() {28 return prop;29 }30 public void setProp(Properties prop) {31 this.prop = prop;32 }33 public car getC() {34 return c;35 }36 public void setC(car c) {37 this.c = c;38 }39 public pay getP() {40 return p;41 }42 public void setP(pay p) {43 this.p = p;44 }45 @Override46 public String toString() {47 return "person [c=" + c + ", p=" + p + ", list=" + list + ", set="48 + set + ", map=" + map + ", prop=" + prop + "]";49 }50 51 52 }
XML:
1 23 4 5 6 7 8 9 10 1611
15啊啊啊啊啊 12啊啊啊啊啊1 13啊啊啊啊啊2 1417 22 2324 3025 29java 26javaaaaaaaaaa 27java 2831 3732 36我们 33你们 34她们 35
测试类:
1 @Test2 public void test(){3 4 ApplicationContext cont = new ClassPathXmlApplicationContext("applicationContext.xml");5 person p = (person) cont.getBean("person");6 System.out.println(p);7 }
结果: