spring annotation注解 @Resource
来源:互联网 发布:电子商务数据分析指标 编辑:程序博客网 时间:2024/05/09 07:16
@Resource的作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入罢了。@Resource有两个属性是比较重要的,分是name和type,Spring将@Resource注解的name属性解析为bean的名字,而type属性则解析为bean的类型。所以如果使用name属性,则使用byName的自动注入策略,而使用type属性时则使用byType自动注入策略。如果既不指定name也不指定type属性,这时将通过反射机制使用byName自动注入策略。
@Resource装配顺序
1. 如果同时指定了name和type,则从Spring上下文中找到唯一匹配的bean进行装配,找不到则抛出异常
2. 如果指定了name,则从上下文中查找名称(id)匹配的bean进行装配,找不到则抛出异常
3. 如果指定了type,则从上下文中找到类型匹配的唯一bean进行装配,找不到或者找到多个,都会抛出异常
4. 如果既没有指定name,又没有指定type,则自动按照byName方式进行装配;如果没有匹配,则回退为一个原始类型进行匹配,如果匹配则自动装配;
0 0
- Spring Annotation(注解) @Resource
- spring annotation注解 @Resource
- spring的annotation注解之@Resource
- spring的annotation注解之@Resource
- Spring 注解 javax.annotation.Resource和@Autowired
- javax.annotation.Resource注解
- javax.annotation.Resource这个注解
- spring annotation 注解 简记
- Spring Annotation(注解) 详解
- Spring Annotation(注解) 详解
- Spring Annotation 注解
- Spring Annotation(注解) @Component
- 【framework】spring-注解(annotation)
- Spring注解Annotation
- annotation(spring注解)
- spring annotation注解 autowire
- spring annotation注解
- Spring---annotation注解初学
- ios xcode6 创建分类和延展
- js 页面跳转整理
- Android电子书项目实训【项目说明】【1】
- hdu3555 数位dp
- Android开机启动Activity或者Service方法
- spring annotation注解 @Resource
- JAVA学习(七):方法重载与方法重写、this关键字和super关键字
- mysql 随机取一条或多条数据 高效率
- Android Studio 中 project 与 module 的关系
- 文章标题
- ZOJ 3526 Weekend Party
- HDU 1198
- listview的getview执行两次
- IE6支持透明PNG图片解决方案:DD_belatedPNG.js