Hello. I've got a problem.
I have a structure of beans like this:
Each of subBeanN contains a list of handlers. Each topBean instance has unique instances of subBeanN, and each of subBeanN contains unique instances of handlers, i.e. there are no singletons.Code:topBean subBean1 handler1 handler2 ... handlerN subBean2 handler1 ... handlerM subBean3 handler1 ... handlerK
Now for some of the beans I have to set the same instance of object Foo into some properties. I naively tried this:
Spring complains that uniqueFoo is not found in handler1. Yeah. Sure.Code:<bean id="topBean" ... > <property name="subBean1" ref="subBean1"/> <property name="foo"> <bean id="uniqueFoo" class="someFactory"/> </property> ... </bean> <bean id="subBean1" ... > <property name="handlers"> <list> <bean id="handler1" class="..."> <property name="foo" ref="uniqueFoo"/> </bean> ...
But if I move bean uniqueFoo out of the topBean, then handler1 will get a different instance than topBean (factory is not singleton one).
I cannot make the factory singleton since there are more than one topBean are created at the same time, and those must have unique instances of foo.
Is there a way to achive what I want through the pure configuration?
May be, there should be one more instance type: unique inside a given bean tree (i.e. from topBean and down)?


Reply With Quote