@Component //该注解让该类会被扫描到,并且成为一个bean
public class CatSay implements Say {
public String say() {
System.out.println("cat say...");
return "cat say...";
}
}
@Component
public class Cat {
private CatSay catSay;
public Cat() {
}
@Autowired //该注解不仅可以用在构造器上,任何需要注入其他bean的方法都可以使用
public Cat(CatSay catSay) {
this.catSay = catSay;
}
public void say(){
catSay.say();
}
}