Spring注解@Resource和@Autowired区别对比
2017-09-09 17:48
651 查看
@Autowired与@Resource的区别
http://bhdweb.iteye.com/blog/1663907
http://www.cnblogs.com/think-in-java/p/5474740.html
简单描述:
@Autowried
由Spring提供,默认是byType方式注入,如果需要byName方式,再设置一个@Qualifar("name"),如果注入的字段或对象可以为null,可以设置required=false,如 @Autowired(required=false)
@Resource
由JDK提供支持的,默认是byName 方式注入,根据反射的原理,根据当前的name来注入。如果需要byType方式,设置 @Resource(type="xxx")
需要name和type都要限定,@Resource(name="",type="")
如果是Spring mvc 需要使用注解,一般有两个配置。
<context:component-scan base-package="cn.xxx,cn.aaa" />
<mvc:annotation-driven />
一般不同时配置。
http://bhdweb.iteye.com/blog/1663907
Spring注解@Resource和@Autowired区别对比
http://www.cnblogs.com/think-in-java/p/5474740.html简单描述:
@Autowried
由Spring提供,默认是byType方式注入,如果需要byName方式,再设置一个@Qualifar("name"),如果注入的字段或对象可以为null,可以设置required=false,如 @Autowired(required=false)
@Resource
由JDK提供支持的,默认是byName 方式注入,根据反射的原理,根据当前的name来注入。如果需要byType方式,设置 @Resource(type="xxx")
需要name和type都要限定,@Resource(name="",type="")
如果是Spring mvc 需要使用注解,一般有两个配置。
<context:component-scan base-package="cn.xxx,cn.aaa" />
<mvc:annotation-driven />
一般不同时配置。
相关文章推荐
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比
- Spring注解@Resource和@Autowired区别对比