0

I have two simple beans. In the first bean it calls a init-method and return string value.

Now I want to this returned string from first bean init-method , inject to my second bean

helloWorldBean3 property newKey. Please advise me on how to implement this requirement.

  <bean id="helloWorldBean2" init-method="loadKey"
 class="com.java.snippets.enterprise.services.HelloWorld2">
 <property name="key" value="${key.supportiveFile}" />

<bean id="helloWorldBean3"
    class="com.java.snippets.enterprise.services.HelloWorld">
       <property name="newKey" ref="???" />
</bean>
Kasun
  • 561
  • 11
  • 22
  • That's not really what an init-method is meant for. I suggest refactoring, making your `loadKey` set a property and have the other bean get that property. – Sotirios Delimanolis Apr 20 '14 at 15:14

1 Answers1

0

Try using Spring EL like so:

<bean id="helloWorldBean3"
    class="com.java.snippets.enterprise.services.HelloWorld">
       <property name="newKey" value=""#{helloWorldBean2.loadKey()}"" />
</bean>
geoand
  • 60,071
  • 24
  • 172
  • 190
  • Thanks. Appreciate for any other suggestions I can use with spring 2.x – Kasun Apr 20 '14 at 23:19
  • @Kasun I don't think you can do anything else that meats your requirements... I think you should refactor your beans – geoand Apr 21 '14 at 09:12