Wiring in Spring: @Autowired, @Resource and @Inject 区别
refer:https://www.baeldung.com/spring-annotations-resource-inject-autowire
主要是查找顺序不一致:
@Resource
- Match by Name
- Match by Type
- Match by Qualifier
优先匹配Name @Resource(name="xx")
若没有传入名字则(即直接@Resource)匹配类型,
若一个类型有两个Bean,则还需匹配Qualifier(@Bean 时的类名或方法名),不然会报错
@Inject
- Match by Type
- Match by Qualifier(多个子类实现时)
- Match by Name
匹配顺序如上
@Autowired
- Match by Type
- Match by Qualifier
- Match by Name
和@Inject 一样,
@Resource @Inject是JSR 的注解, 而@Autowire是Spring的注解