Sep 17th, 2009, 03:34 PM
Creating Sub-Container in XML
i have been using many other IoC-Containers with nice features some time ago but following the mainstream I have switched to springframework after common annotations have been supported and XML-programming-style pain has ended.
Now I am missing a powerful feature. A typical IoC-Container has the concept of creating sub-containers. Now what I would like to do is to create a sub-container within my XML configuration and this way be able to override a bean when importing some other XML-configuration.
To make an example:
I have interface A with AImpl
Then interface B with BImpl that requires an instance of A via @Resource.
therefore I have b.xml as
<bean id="A" class="AImpl"/>
<bean id="B" class="BImpl"/>
Easy so far.
Now I have C and CImpl that requires an instance of B via @Resource.
But I also have a AImpl2 that extends AImpl and want to use this
for my CImpl.
What I want is something like:
<bean id="A" class="AImpl2"/>
<bean id="C" class="CImpl"/>
<!-- Indicates that beans is a sub-container that inherits
from this parent -->
My expectation would be that in the resulting container there is
only one bean with id "A" and only one bean that is instance of A
and therefore @Resource injection is unique but will receive AImpl2 rather than AImpl.
Maybe this can already be expressed in some way.
Or somebody can give me a hint how to solve my problem in another way.
Or it could help as an inspiration for a new feature in further spring versions.
What I am not keen on is a solution that requires my code to depend on springframework.