@Autowired
@Resource
@Qualifier
相同点:都是在Ioc容器注入Bean时的注解
不同点:
1.@Resource
注解是J2EE提供的,其他两个是Spring提供的;
2. @Autowired
注解按照byType注入; @Autowired
结合@Qualifier
注解可以实现按照byName注入;
@Resource默认按照byName注入,@Resource有两个重要的属性:name和type,而Spring将@Resource注解的name属性解析为bean的名字,而type属性则解析为bean的类型。
注:最好是将@Resource放在setter方法上,因为这样更符合面向对象的思想,通过set、get去操作属性,而不是直接去操作属性。
3.@Resource的作用相当于@Autowired,只不过@Autowired按照byType自动注入。