0

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>
DD.
  • 21,498
  • 52
  • 157
  • 246
  • Can you add a little more context? Is there a reason you'd do this as opposed to having a property inject the same value into both beans. – Jherico Jul 19 '10 at 19:31
  • Lets say I have a bean like User and I want to inject user.getLastLoginDate() into a loginBean.setLastLoginDate(Date date). This is quite normal thing to do in a faces-config. – DD. Jul 19 '10 at 20:34

2 Answers2

0

Upgraded to Spring 3.0 which has spring el support

DD.
  • 21,498
  • 52
  • 157
  • 246
-1

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.

Jose Diaz
  • 5,353
  • 1
  • 31
  • 29