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


Reply With Quote