@resource
1.@Resource 注解被用来激活一个命名资源(named resource)的依赖注入,
3.@Resource默认按 byName自动注入(名字相匹配)
@Resource(name="dataSource") public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; }
@Resource注解甚至不需要一个显式的字符串值,在没有提供任何值的情况下,域名将被当作默认值。
@Resource private DataSource dataSource; // inject the bean named 'dataSource'
@autowired
1.@Autowired按byType自动注入(bean的类型相匹配)
@Required
1.@Required注解检查,但他只检查属性是否已经设置而不会测试属性是否非空
2.@Required只能设置在setter方法上
3.@Required就是注解这个属性是否已经设值,如果没有设值就会抛BeanInitializationException
参考原文: http://www.yiibai.com/spring/spring_required_annotation.html