spring框架学习(9)bean的自动装配

Bean的自动装配

1、自动装配是spring满足bean依赖的一种方式
2、spring会在上下文寻找,并自动给bean装配属性

在spring中有三种装配方式

1、在xml中显示装配
2、在java中显示装配
3、隐示的自动装配

自动装配

1.环境搭建






import com.yms.entiry.People;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**

  • @Author 杨明书

  • @PackageName: PACKAGE_NAME

  • @ClassName: MyTest

  • @Description:

  • @Date: 2021/12/29 16:39
    */
    public class MyTest {

    public static void main(String[] args) {

    People people = new ClassPathXmlApplicationContext("beans.xml").getBean("people", People.class);
    people.getDog().dogShut();
    people.getCat().shut();
    System.out.println(people.toString());
    }
    }

自动装配

posted @ 2021-12-29 16:50  এএ᭄念卿এএ᭄  阅读(62)  评论(0)    收藏  举报