Nov 2nd, 2006, 10:57 AM
Factory for generating multiple beans
I'm looking for a way to write something like a FactoryBean which can generate multiple beans for the application context. The reason for this is that I have a legacy component with its own configuration file, and this component exposes a collection of beans. I'd like to automatically register those beans with the spring application context, rather than individually fetch them from a vanilla FactoryBean.
The spring ref docs don't seem to have anything that covers this pattern. Any ideas?
Nov 2nd, 2006, 11:35 AM
You probably would be better off implementing BeanFactoryPostProcessor than FactoryBean. A postprocessor can register new bean definitions perfectly sensibly. To register singletons (your use case) you need registerSingleton(String, Object) from DefaultSingletonBeanRegistry.
Last edited by Dave Syer; Nov 2nd, 2006 at 11:40 AM.
Nov 2nd, 2006, 11:57 AM
Ah excellent, that's a great idea