• @Autowired与@Resource用法


    官方文档中有这样一段话。

    If you intend to express annotation-driven injection by name, do not primarily use @Autowired, even if is technically capable of referring to a bean name through @Qualifier values. Instead, use the JSR-250 @Resource annotation, which is semantically defined to identify a specific target component by its unique name, with the declared type being irrelevant for the matching process.

    As a specific consequence of this semantic difference, beans that are themselves defined as a collection or map type cannot be injected through @Autowired, because type matching is not properly applicable to them. Use @Resource for such beans, referring to the specific collection or map bean by unique name.

    @Autowired applies to fields, constructors, and multi-argument methods, allowing for narrowing through qualifier annotations at the parameter level. By contrast, @Resource is supported only for fields and bean property setter methods with a single argument. As a consequence, stick with qualifiers if your injection target is a constructor or a multi-argument method.

  • 相关阅读:
    密码 (pasuwado)
    bzoj 4131: 并行博弈 (parallel)
    Beads
    bzoj2338数矩形(rectangle)
    数树数
    最近公共祖先(lca)
    在python中遍历字典元素
    加载本地json文件,并利用批处理调用Chrome显示html
    numpy保存数据
    Echarts 地理信息可视化:基于地图显示坐标点信息
  • 原文地址:https://www.cnblogs.com/shizhongtao/p/3436569.html
Copyright © 2020-2023  润新知