Announcement Announcement Module
Collapse
No announcement yet.
Advising bean instantiation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advising bean instantiation

    I have a rather complex requirement. I need to ensure that for certain beans a dynamic context is established during their instantiation. I.e. something like:

    Code:
    Context.push(...)
    Foo foo = new Foo(...);
    Context.pop();
    The beans themselves do not directly know about the dynamic context; I can't just inject it into them.

    I've read about InstantiationAwareBeanPostProcessorAdapter and it's almost what I need: it has postProcessBeforeInstantiation and postProcessAfterInstantiation methods that let you control what happens before and after Spring instantiates a bean. However, it has a weakness: it doesn't give any callback in case the instantiation fails; in my case, that would cause the dynamic context to be never cleaned up.

    Is there any other solution for my need? If no, would it make sense for Spring to enhance the InstantiationAwareBeanPostProcessor interface to include an instantiationFailed callback method?

    TIA,
    Alessio
Working...
X