Spring---bean的命名
每个Bean可以有一个或多个 id,我们把第一个 id 称为“标识符”,其余id叫做“别名”,这些id在 IoC 容器中必须唯一。
Bean id 的命名约定:
- 遵循XML命名规范
- 由字母,数字,下划线组成
- 驼峰式,首个单词字母大写
Bean id 的命名方式:
- 配置全限定类名,唯一
- 指定id,唯一
- 指定name,唯一
- 指定id和name,唯一
- 指定多个name,唯一
- 指定别名,唯一
<!-- 配置全限定类名 -->
<bean class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
<!-- 指定id -->
<bean id="helloWorld" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
main中
beanFactory.getBean("helloWorld" , helloWorld.class);
<!-- 指定name -->
<bean name="helloWorldByName" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
main中
beanFactory.getBean("helloWorld" , helloWorld.class);
<!-- 指定id和name -->这样既可以通过id,也可以通过name获取到类的实例
<bean id="helloWorldById" name="helloWorldByName01" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
<!-- 指定多个name -->
<bean name="bean1;alias11;alias12;alias13" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
<bean id="bean2" name="alias21,alias22,alias23" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
<!-- 指定别名 -->
<bean name="bean3" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
<alias alias="alias31" name="bean3" />
<alias alias="alias32" name="bean3" />
Spring---bean的命名的更多相关文章
- Spring bean自定义命名策略(注解实现)
我们都知道项目后台开发是从 控制层——业务层——mybatis层,@Controller.@Service.@Mapper...等等注解可以将对象自动加载到bean容器中,还能实现相应的功能,使用起来 ...
- Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别
Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...
- (转)Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别
Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...
- Spring中Bean的命名问题及ref和idref之间的区别
一直在用Spring,其实对其了解甚少,刚去了解了一下Spring中Bean的命名问题以及ref和idref之间的区别,略作记录,以备后查. Spring中Bean的命名 1.每个Bean可以有一个i ...
- Spring学习笔记——02 Bean的命名及实例化
一.Bean的命名 前一篇讲到IoC是一个管理Bean的容器,Bean多数情况下都是通过XML文件进行配置的,其中Bean的命名有以下几种方式,现在梳理一下. 1. 不指定id,只配置类名 <b ...
- Spring Framework5.0 学习(4)—— Bean的命名id和name区别
Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...
- Spring Bean详细讲解
什么是Bean? Spring Bean是被实例的,组装的及被Spring 容器管理的Java对象. Spring 容器会自动完成@bean对象的实例化. 创建应用对象之间的协作关系的行为称为:装配( ...
- Spring(3)——装配 Spring Bean 详解
装配 Bean 的概述 前面已经介绍了 Spring IoC 的理念和设计,这一篇文章将介绍的是如何将自己开发的 Bean 装配到 Spring IoC 容器中. 大部分场景下,我们都会使用 Appl ...
- spring @Bean注解的使用
@Bean 的用法 @Bean是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里.添加的bean的id为方法名 定义bean 下面是@Co ...
- 对Spring Bean了解一二
这之前从未听说过Spring Bean,今天因为学习的<Java核心36讲>其中一篇涉及到了这个内容,因自己基础薄弱,杨晓峰老师讲的内容需要一定的基础才能看懂,故在网上搜罗一些我能理解的关 ...
随机推荐
- 服务器raid状态监控
参考 http://hwraid.le-vert.net/wiki 查看raid芯片 lspci -v 02:00.0 SCSI storage controller: LSI Logic / Sym ...
- JAVA StringBuffer的用法
在使用StringBuffer 的时候,习惯性的像String一样把他初始化了 StringBuffer result = null; 结果警告:Null pointer access: The va ...
- Saw a tweet from Andrew Liam Trask, sounds like Oxford DeepNLP 2017 class have all videos slides practicals all up. Thanks Andrew for the tip!
Saw a tweet from Andrew Liam Trask, sounds like Oxford DeepNLP 2017 class have all videos/slides/pra ...
- Element-ui(el-table、el-pagination)实现表格分页
HTML代码:(重点关注el-table中:data数据的绑定) el-pagination中: layout代表组件布局,子组件名用逗号分隔 属性: total代表总条目数 事件: current- ...
- COGS 2091. Asm.Def的打击序列
★★★ 输入文件:asm_lis.in 输出文件:asm_lis.out 简单对比时间限制:4 s 内存限制:256 MB [题目描述] 白色圆柱形的“蓝翔”号在虚空中逐渐变大,一声沉 ...
- IOS 公司标示和方向域名
1. 公司标示使用反向域名========================================正向域名 www.baidu.com 用来标示一台网络主机反向域名 cn.itcast.Myd ...
- @RequestMapping,@ResponseBody,@RequestBody用法
本文转载:http://blog.csdn.net/ff906317011/article/details/78552426 1.@RequestMapping 国际惯例先介绍什么是@RequestM ...
- 【转】Data URL和图片,及Data URI的利弊
Data URL给了我们一种很巧妙的将图片“嵌入”到HTML中的方法.跟传统的用img标记将服务器上的图片引用到页面中的方式不一样,在Data URL协议中,图片被转换成base64编码的字符串形式, ...
- 文本编辑器Vim技巧
1. 导入文件内容 :r 文件名 2. 插入当前日期 :r !date 3. :!which ls 4. :r !命令
- LSD-SLAM使用方法
preparation:按照官網步驟完成LSD的安裝. 1.testdata:need images file & cameraCalibration.cfg 2.開啟終端機 -> ...