Passing spring constructor-arg to another ref bean
I have following class which I am trying to instantiate through spring.
class MyBean{
MyBean myBeanFallback;
MyDataObject myDataObject;
public void setMyBeanFallback(MyBean myBeanFallback){
this.myBeanFallback = myBeanFallback;
}
MyBean(MyDataObject myDataObject){
this.myDataObject = myDataObject;
}
}
Following is the spring config I am tryin got use to load this :
<bean name="myNewBean" class="MyBean"
scope="prototype">
<constructor-arg index="0" type="MyDataObject" >
<null />
</constructor-arg>
<property name="myBeanFallback" ref="myOldBean" />
</bean>
<bean name="myOldBean" class="MyBean"
scope="prototype">
<constructor-arg index="0" type="MyDataObject" >
<null />
</constructor-arg>
</bean>
In my application code, I may instantiate the myOldBean which has data and
no fallback. else I may instantiate the myNewBean which has data and also
has myOldBean as fallback, which in turn also needs to have same
myDataObject
getNewBean(MyData mydata){
return (MyBean) context.getBean("myNewBean", new Object[] { mydata });
}
getOldBean(MyData mydata){
return (MyBean) context.getBean("myOldBean", new Object[] { mydata });
}
The problem I am facing now is that while getting myNewBean, the fallback
getNewBean doesn't get populated with mydata, rather takes null.
Any pointers on how this can be fixed ?
No comments:
Post a Comment