Spring 依赖项注入返回bean init方法的结果

Spring 依赖项注入返回bean init方法的结果,spring,inversion-of-control,spring2.x,Spring,Inversion Of Control,Spring2.x,我有两个简单的豆子。在第一个bean中,它调用init方法并返回字符串值 现在,我想将第一个bean init方法返回的字符串注入到第二个bean中 helloWorldBean3属性newKey。请告诉我如何实施这一要求 <bean id="helloWorldBean2" init-method="loadKey" class="com.java.snippets.enterprise.services.HelloWorld2"> <property name="k

我有两个简单的豆子。在第一个bean中,它调用init方法并返回字符串值

现在,我想将第一个bean init方法返回的字符串注入到第二个bean中

helloWorldBean3属性newKey。请告诉我如何实施这一要求

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


尝试使用Spring EL,如下所示:

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

这并不是init方法的真正用途。我建议重构,让你的loadKey设置一个属性,让另一个bean获得这个属性。谢谢。感谢您对Spring2的其他建议。x@Kasun我认为你不能做任何符合你要求的事情。。。我认为你应该重构你的豆子
<bean id="helloWorldBean3"
    class="com.java.snippets.enterprise.services.HelloWorld">
       <property name="newKey" value=""#{helloWorldBean2.loadKey()}"" />
</bean>