Dependency Injection returned results of bean init-method

116 Views Asked by At

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>
1

There are 1 best solutions below

2
On

Try using Spring EL like so:

<bean id="helloWorldBean3"
    class="com.java.snippets.enterprise.services.HelloWorld">
       <property name="newKey" value=""#{helloWorldBean2.loadKey()}"" />
</bean>