Announcement Announcement Module
No announcement yet.
non-singleton bean re-references Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • non-singleton bean re-references

    I have a bean A which cannot be a singleton. I need to inject it into B. no problem. I also need to inject it into C, which is in turn injected into B. The A held by B and C need to be the exact same instance.

    Is this possible somehow?

    (I'm not real keen on this design, but for the sake of discussion, assume it really is required to be this way).


  • #2
    A way to achieve this is by implementing a FactoryBean that returns the same object. A property of such bean will be your bean A (that you will return from the getObject() method). Then inject the factory instance in B and C.