Results 1 to 3 of 3

Thread: Factory for generating multiple beans

  1. #1
    Join Date
    Aug 2005
    Posts
    39

    Default 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?

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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.

  3. #3
    Join Date
    Aug 2005
    Posts
    39

    Default

    Ah excellent, that's a great idea

    Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •