[英]How to set bean property value from other bean property value
例如,我们有带字符串属性propertyA的 bean beanA :
<bean name="beanA" class="...">
<property name="propertyA"><value>some string value </value></property>
</bean>
第二个bean beanB也具有字符串属性propertyB,并且我想使用与beanA.propertyA相同的值来初始化此属性,我认为我需要执行以下操作:
<bean name="beanB" class="...">
<property name="propertyB"><value>beanA.propertyA</value></property>
</bean>
但这是行不通的,表达式beanA.propertyA威胁为字符串值。
可能这与IoC理论背道而驰,Spring不支持。
谢谢。
util名称空间具有一些非常有用的功能。
您可以使用<util:property-path id="name" path="testBean.age"/>
在Spring 3中,您还可以使用Spring Expression语言 :
<bean name="beanB" class="...">
<property name="propertyB"><value>#{ beanA.propertyA }</value></property>
</bean>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.