I want to create a bean that will act as a provider.
I will give it the class that it should return and the list of properties that I should set before returning it.
so basically it looks like this:
<bean id="somethingFactory" class="foo.bar.SomethingFactory">
<property name="implClass" value="foo.bar.SomehtingImpl" />
<property name="properties">
<props>
<prop key="prop1">prop1Value</prop>
<prop key="prop2">prop2Value</prop>
</props>
</property>
</bean>
The “SomethingFactory” has a provide() method that will return an instance of “SomehtingImpl”.
The question is how can I use Spring to do it?
Make SomethingFactory a
FactoryBean, extendAbstractFactoryBeanand use aBeanWrapperto populate the properties from the input parameters.Here’s a sample implementation: