I am trying to write a simple plugin system for the core of our application so that client modules can supply their own implementations.
I've created a delegate bean that is configured through spring xml to always a reference to the default core implementation. I would also like to have it reference a client bean that may or may not exist. Whether or not a client wants to provide extra xml bean definitions is up to them.
Basically, I'd like to have something like:
<bean id="myBeanDelegate" class="MyBeanDelegate">
<property name="coreBean" ref="coreBean"/>
<property name="clientBean" ref="clientBean"/>
<bean id="coreBean" class="MyCoreBean"/>
And then optionally in a seperate xml file.
<bean id="clientBean" class="MyClientBean"/>
This way the delegate can use the core methods unless a client provides an alternate implementation. The problem with this is that when the client doesn't supply that 'clientBean' the container throws up.
The way I've worked around this for now is to not define the clientBean reference in the core xml file. Instead, I give the clientBean a reference to the delegate via setter injection. Once I have the reference to the delegate in the client's setter, I can then provide the delegate with a reference to the client. This works, but it seems far from elegant.
Can anyone suggest a cleaner alternative?
Please let me know if I'm being unclear.