Spring ref属性配置
来源:互联网 发布:squid软件 编辑:程序博客网 时间:2024/05/20 12:48
在<constructor-arg/>
或<property/>
元素内部还可以使用ref
元素。该元素用来将bean中指定属性的值设置为对容器中的另外一个bean的引用。如前所述,该引用bean将被作为依赖注入,而且在注入之前会被初始化(如果是singleton bean则已被容器初始化)。尽管都是对另外一个对象的引用,但是通过id/name指向另外一个对象却有三种不同的形式,不同的形式将决定如何处理作用域及验证。
第一种形式也是最常见的形式是通过使用<ref/>
标记指定bean
属性的目标bean,通过该标签可以引用同一容器或父容器内的任何bean(无论是否在同一XML文件中)。XML 'bean
'元素的值既可以是指定bean的id
值也可以是其name
值。
<ref bean="someBean"/>
第二种形式是使用ref的local
属性指定目标bean,它可以利用XML解析器来验证所引用的bean是否存在同一文件中。local
属性值必须是目标bean的id属性值。如果在同一配置文件中没有找到引用的bean,XML解析器将抛出一个例外。如果目标bean是在同一文件内,使用local方式就是最好的选择(为了尽早地发现错误)。
<ref local="someBean"/>
第三种方式是通过使用ref的parent
属性来引用当前容器的父容器中的bean。parent
属性值既可以是目标bean的id
值,也可以是name
属性值。而且目标bean必须在当前容器的父容器中。使用parent属性的主要用途是为了用某个与父容器中的bean同名的代理来包装父容器中的一个bean(例如,子上下文中的一个bean定义覆盖了他的父bean)。
<!-- in the parent context --><bean id="accountService" class="com.foo.SimpleAccountService"> <!-- insert dependencies as required as here --></bean>
<!-- in the child (descendant) context --><bean id="accountService" <-- notice that the name of this bean is the same as the name of the 'parent'
bean class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target"> <ref parent="accountService"/> <-- notice how we refer to the parent bean </property> <!-- insert other configuration and dependencies as required as here --></bean>源自:http://blog.csdn.net/xianyu_0418/article/details/4369891ss
0 0
- Spring ref属性配置
- Spring property标签ref属性和ref标签区别
- Spring中引用标签ref和属性ref
- Spring框架xml配置中属性 ref 与 value的区别
- Spring 配置文件 属性 ref bean和local的区别
- 关于spring配置文件中 ref 属性的设定
- Spring中p:属性及ref的用法总结
- Spring 配置文件中元素 'ref' 中不允许出现属性 'local'
- spring中用ref属性指定的三种方法
- Spring中提示元素 'ref' 中不允许出现属性 'local'
- spring笔记——ref属性的设定
- Spring中提示元素 'ref' 中不允许出现属性 'local'。
- spring property标签中的 ref属性和ref 标签有什么不同? 如下:<property name="a" ref="b" />
- spring property标签中的 ref属性和ref 标签有什么不同? 如下:<property name="a" ref="b" />
- applicationContext.xml 配置属性和对象ref指向
- Spring配置bean属性
- spring 配置属性细节
- spring 属性配置
- mysql操作笔记
- Spring 中的default-lazy-init="true" 和 lazy-init="true"
- 斜率优化专题5——bzoj 1096 [ZJOI2007]仓库建设 题解
- Spring 反射注入+全注解注入
- 不要只和结婚的人谈恋爱 //转自《拆掉思维里的墙》
- Spring ref属性配置
- C++/C博客记录
- [BZOJ1041][HAOI2008][数学乱搞]圆上的整点
- android中intent带Uri传输时中文的乱码问题
- Nginx自定义模块编写:根据post参数路由到不同服务器
- codechef The Ball And Cups题解
- mini2440之--leds程序
- maven项目添加jar包.
- the msi failed