[英]Java Spring IOC bean creation value
我需要这样的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方法设置新的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>
任何解决方法。
抱歉,我的英语不好,非常感谢您的帮助。
委内瑞拉最好的问候。
如果我对您的理解正确,那么将使用studentWithSchool
方法创建并返回anotherBean
。 如果是这样,您可以使用工厂方法 :
<bean id="studentWithSchool" factory-bean="anotherBean" factory-method="getBeanProperty" scope="prototype" />
我相信您正在尝试在Spring中使用工厂模式。 为此,您可以从春季开始使用工厂bean。
<bean id="studentWithSchool" factory-bean="anotherBeanStaticFactory" factory- method="createBeanProperty" scope="prototype"
<property name="school">
<bean class="com.model.School" scope="prototype"/>
</property>
有关更多详细信息,您可以使用以下链接:-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.