2014-12-05 32 views
0

我需要一个bean这样的Java的Spring IoC bean创建值

<bean id="studentWithSchool" class="com.model.Student" scope="prototype">  
    <property name="school"> 
     <bean class="com.model.School" scope="prototype"/> 
    </property> 
</bean> 

这是确定。

我的问题是我有学生从不同的bean的方法返回。

我通常像这样加载bean是属性。

<property name='beanProperty' value='#{anotherBean.getBeanProperty()}'/> 

但在这种情况下,我需要新豆自身与其它bean方法(School object is returned from another bean method)被设置。

这是我所尝试的,当然这是错误的。

<bean id="studentWithSchool" class="com.model.Student" scope="prototype" value='#{anotherBean.getBeanProperty()}'>  
    <property name="school"> 
     <bean class="com.model.School" scope="prototype"/> 
    </property> 
</bean> 

任何解决方法。

我的英语不好对不起,任何帮助是巨大的赞赏...

来自委内瑞拉最好的问候。

回答

1

如果我的理解正确,studentWithSchool被创建并通过anotherBean中的方法返回。如果是这样的话,你can use a factory-method

<bean id="studentWithSchool" factory-bean="anotherBean" factory-method="getBeanProperty" scope="prototype" /> 
+0

它的工作原理就像一个魅力最好的问候:) – chiperortiz 2014-12-06 12:05:18