AutoWired自动装配
现在由Person,Dog,Cat
Person里有Dog和Cat
以前的做法是Person里通过set或构造器设置Dog和Cat
现在利用autowired属性或者@AutoWired注释搞定
下面演示普通做法,属性,注释三种情况
普通做法
-
写三个类
package com.xxx; public class Cat { public void show() { System.out.println("我是猫猫,喵喵喵..."); } }
package com.xxx; public class Dog { public void show() { System.out.println("我是狗狗,汪汪汪..."); } }
package com.xxx; import org.springframework.beans.factory.annotation.Autowired; public class Person { private Cat cat; private Dog dog; public void setCat(Cat cat) { this.cat = cat; } public void setDog(Dog dog) { this.dog = dog; } public <