1.两者的区别
@Autowired注解是Spring自己定义的(只按照byType注入);@Resource注解是JSR-250规范定义的(由J2EE提供,默认是按照byName自动注入)
2.@Resource注解
@Resource有两个重要的属性,name和type。
Spring将@Resource注解的name属性解析为bean的名字,type属性则解析为bean的类型。所以如果使用name属性,则使用byName的自动注入策略;而使用type属性则使用byType自动注入策略;如果既不指定name也不指定type属性,这时通过反射机制使用byName自动注入策略。
@Resource的作用是相当于@Autowired,只不过@Autowired是按照byType进行装配。