Hi,
I have several beans whose implementation class is different for each customer. For the sake of simplicity assume there are just 2 beans (paint and carpet) and 2 customers (red and blue)
Manually including/excluding the correct beans is annoying, particularly when there are many customers/beans.Code:<!-- Include one or other of the 2 sets of beans below, depending on whether we are building for the red or blue customer --> <bean id="paint" class="com.paint.RedPaint" /> <bean id="carpet" class="com.carpet.RedCarpet" /> <bean id="paint" class="com.paint.BluePaint" /> <bean id="carpet" class="com.carpet.BlueCarpet" />
What I would like to do is define an abstract factory interface like this:
And a bean in the Spring config that provides a customer-specific implementation of this factory:Code:interface CustomerFactory { Paint getPaint(); Carpet getCarpet(); }
Now if I want to build the application for the red customer I only need to change one thingCode:<bean id="customerFactory" class="com.customer.BlueFactory" />
However, there's one thing I don't know how to do......how to create the "paint" and "carpet" beans by calling a method of the "customerFactory" bean?Code:<bean id="customerFactory" class="com.customer.RedFactory" />
In the Spring docs an example is given of how to create a bean by calling a factory method of a class, but that's not what I need here, I want a way to create a bean by calling a method of a bean.
Regards,
DM


Reply With Quote
