Spring MVC学习笔记(三) @Resource

     There is a wonderful feeling when I make the notes using Internet rather than local papers.

  "遗留问题":转配bean对象做什么???????"装配"到底做了什么事情/??/

  自动"装配"bean对象

  @Autowired   @Resource

  @Autowired用于字段上
      private PersonDao personDao;  

            @Autowired用于属性的setter方法上

      public void setOrderDao(OrderDao orderDao){

        this.orderDao = orderDao;

      }

  @Autowired默认按类型装配,默认情况下它要求依赖对象必须存在,如果允许null值,可以设置required属性为false.

..  
@Resource注解一样,也可以标注才"字段"或者"属性的setter方法"上,但它默认按名称装配.名称可以通过@Resourcede的name 属性指定,@Resource(name="userDao"),如果没有指定name属性,当注解标注在"字段"上,即默认取属性名作为bean名称寻找依赖对象.

不要说话
原文地址:https://www.cnblogs.com/sxudk/p/4450813.html