can spring容器XML配置引用使用另一个bean'property(can spring container XML config reference use another bea

编程入门 行业动态 更新时间:2024-10-24 02:29:35
can spring容器XML配置引用使用另一个bean'property(can spring container XML config reference use another bean'property)

我在这里写一个spring应用程序,这里我想做的是这样的:

<bean id="sqlClient" class="com.braoda.dao.sqclient.SqlclientWapper"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="userDao" class="com.braoda.dao.user.UserDaoImpl"> <property name="sqlSession" ref="***sqlClient.SqlSessionFactoryBean***" />

就像代码一样,我想从“ref”使用spring Xml属性config,但是“ref”不是bean而是bean的属性。 这在春天是非法的,或者我们不能像这样使用春天。

Here I am writing a spring application, here I want to do is like this:

<bean id="sqlClient" class="com.braoda.dao.sqclient.SqlclientWapper"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="userDao" class="com.braoda.dao.user.UserDaoImpl"> <property name="sqlSession" ref="***sqlClient.SqlSessionFactoryBean***" />

As the code like, I want use the spring Xml property config from "ref", but "ref" is not a bean but a bean's property. is this illegal in spring or we can not use spring like this.

最满意答案

对的,这是可能的。

看看http://forum.spring.io/forum/spring-projects/container/35869-reference-bean-property-within-reference

它显示的代码如<property name="username" value="${local.username}"/>

Yes, it is possible.

have a look at http://forum.spring.io/forum/spring-projects/container/35869-reference-bean-property-within-reference

which shows code like <property name="username" value="${local.username}"/>

更多推荐

本文发布于:2023-08-07 03:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1461218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   bean   XML   spring   config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!