一.属性自动装配
首先,准备三个类,分别是User,Cat,Dog。其中User属性拥有Cat和Dog对象。
1 package com.hdu.autowire; 2 3 public class User { 4 private Cat cat; 5 private Dog dog; 6 private String str; 7 8 public Cat getCat() { 9 return cat; 10 } 11 public void setCat(Cat cat) { 12 this.cat = cat; 13 } 14 public Dog getDog() { 15 return dog; 16 } 17 public void setDog(Dog dog) { 18 this.dog = dog; 19 } 20 public String getStr() { 21 return str; 22 } 23 public void setStr(String str) { 24 this.str = str; 25 } 26 }