We have a white labeled application (one application supporting a branded experience for multiple customers). We would like to be able to load a co-brand version of a component to support custom components per customer. For example something like:
<!-- default service -->
<bean id="service" class="com.blah.myService" primary="true">
<property name="myBean" ref="bean" />
</bean>
<!-- custom service for client 123 -->
<bean id="service_123" class="com.blah.myService">
<property name="myBean" ref="bean" />
</bean>
<!-- default bean -->
<bean id="bean" class="com.blah.Bean" primary="true"/>
<!-- bean for client 123 -->
<bean id="bean_123" class="com.blah.Bean" />
We have tried subclassing the ApplicationContext, and this works for the top-level bean, but the autowired collaborators are wired and cached during the loading of spring.
As an example, if I invoke getBean("service"), I can intercept the call in my custom ApplicationContext and return service_123, but the "bean" property uses the cached version and does not invoke the getBean method again, thus I am unable to wire in the custom version.
Is there an easy way to achieve this type of runtime custom injection?