开发者

Spring El Expression

I'm switching from faces-config to Spring and wanted to know how you can pass a property from one bean to another:

e.g.

<bean id="myBean" 开发者_JAVA技巧class="Bean1">

 </bean>
 <bean id="myBean2" class="Bean2">
    <constructor-arg ref="#{myBean1.value}"/>
 </bean>


Upgraded to Spring 3.0 which has spring el support


First things first, the purpose of the D.I container is to fully initialize your system prior to execution; that is, all dependencies being set, the app is ready to run.

There are both @property and @value annotations in Spring for similar purposes, but since you want to use and specific bean property value for other bean the best solution would be:

<bean id="myBean" class="Bean1">

 </bean>
 <bean id="myBean2" class="Bean2">
    <constructor-arg ref="myBean"/>
 </bean>

If you argue that you just want to set the value at instantiation time, and not establish a dependency, then skip the D.I part and set the value directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜