Results 1 to 5 of 5

Thread: FactoryBean: injecting to returned bean.

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    5

    Default FactoryBean: injecting to returned bean.

    How do you set a property on a bean returned by a FactoryBean? You can set properties on the FactoryBean itself, but I need to inject into the returned object. I'm looking for a solution that does not involve altering the FactoryBean implementation and preferably does not involve writing any code.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is there any reason you don't want to change the FactoryBean?
    Last edited by karldmoore; Aug 27th, 2007 at 03:31 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jul 2007
    Posts
    5

    Default FactoryBean: injecting into returned bean.

    Nothing is stopping me from changing the FactoryBean, but I thought it might be simpler to do this through configuration, if possible.

    The other way is to create a setter on the FactoryBean that takes a Map (key = property name, value = object). When getObject is called, the FactoryBean would retrieve the object from a legacy (non-spring) context and set the dependencies on the returned object based on values in the Map: the property names in the map would correspond to properties on the returned object.

  4. #4
    Join Date
    Jul 2007
    Posts
    5

    Default Problem solved

    I solved the problem by modifying the FactoryBean implementation to inject spring beans into the object that's looked up from the legacy context.

    In the app context xml I pass in a map of property/value pairs to the FactoryBean. The getObject method in the FactoryBean impl then injects the values into the object before returning.

    Spring should provide some way to inject into any bean, even if spring does not create the bean.

  5. #5
    Join Date
    Aug 2004
    Location
    New York, NY
    Posts
    74

    Default

    Hi,

    Just FYI, this type of functionality was added to Spring.NET. A new interface IConfigurableFactoryObject was created with the property, ProductTemplate. There you can configure the product that the IFactoryObject creates. (To convert to java, remove leading 'I' and replace object with bean ).

    Here are the docs and an example.

    Cheers,
    Mark

Posting Permissions

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