views:

28

answers:

2

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" class="Bean1">

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

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.

StudiousJoseph
A: 

Upgraded to Spring 3.0 which has spring el support

DD