zoukankan      html  css  js  c++  java
  • @Autowired和@Resource注解的区别?

    谈到Spring的注解,@Autowired和@resource这两个注解不得不提。@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上

    那@Autowired和@resource注解的区别是什么?

    1.@Autowired是spring的注解,它的jar包在import org.springframework.beans.factory.annotation.Autowired。而@resource是属于java的,它的jar包在import javax.annotation.Resource;

    2. @Autowired默认按类型装配byType,默认情况下必须要求依赖对象必须存在,如果要允许null值,可以设置它的required属性为false,如:@Autowired(required=false) ,如果我们想使用名称装配可以结合@Qualifier注解进行使用。@Resource注解默认按 byName自动注入,如果没有指定name属性,当注解写在字段上时,默认取字段名进行安装名称查找,如果注解写在setter方法上默认取属性名进行装配。当找不到与名称匹配的bean时才按照类型进行装配。

    你一直说自己没努力,那你努力100%试一下啊。你的天空你不想飞一下吗?
  • 相关阅读:
    python模块--time模块
    python模块--如何相互调用自己写的模块
    Animating Views Using Scenes and Transitions
    fragment 切换
    android textview 设置text 字体
    android intent 5.1
    android EditView ime
    animation of android (4)
    animation of android (3)
    animation of android (2)
  • 原文地址:https://www.cnblogs.com/boy4j/p/7100270.html
Copyright © 2011-2022 走看看