This interface is equivalent to org.springframework.beans.factory.ObjectFactory<T>
that is typically used to avoid BeanFactory.getBean()
calls in client code when looking for prototype instances. Often used with ObjectFactoryCreatingFactoryBean
to get prototypes beans sourced by the BeanFactory
.
example from ObjectFactoryCreatingFactoryBean
javadocs:
<beans>
<!-- Prototype bean since we have state -->
<bean id="myService" class="a.b.c.MyService" scope="prototype"/>
<bean id="myServiceFactory"
class="org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean">
<property name="targetBeanName"><idref local="myService"/></property>
</bean>
<bean id="clientBean" class="a.b.c.MyClientBean">
<property name="myServiceFactory" ref="myServiceFactory"/>
</bean>
</beans>
With Providers
, you can use the ProviderCreatingFactoryBean
instead.
Other option to solve the same problem, (using inheritance instead composition) is the lookup method injection