What is the best way to making two prototype beans aware of each other?
Clearly cycles in a bean dependency graph won't work:
causes Spring to loop until out of memory.Code:<beans> <bean id="a" class="RefBean1" singleton="false"> <property name="ref"><ref bean="b"/></property> </bean> <bean id="b" class="RefBean2" singleton="false"> <property name="ref"><ref bean="a"/></property> </bean> </beans>
Defining :
gives the same problem.Code:<bean id="b" class="RefBean2" singleton="false"> <lookup-method name="lookupA" bean="a"/> </bean>
Presumably this is because Spring tries to build a chain of instances A->B->A->B... .
What I really want is A<=>B, i.e. A is supplied with a B instance and the B instance is made aware of the A instance.
What is the best approach to handling this? Can this be done without making one of the beans a Singleton?


Reply With Quote