-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Ben Rowlands opened SPR-3315 and commented
Often its desirable to modify a bean definition, for example detecting annotations and updating the definition.
This can almost be done using a BeanFactoryPostProcessor and the getBeanDefintionNames() and getBeanDefintion(String) API on the application context, however this doesn't handle inner beans.
A BeanDefinitionVisitor could be used but this is very inefficent if multiple of these are involved.
Could a BeanDefinitionPostProcessor be added? It would be invoked during the bean creation lifecycle with the merged bean definition, following a similar pattern to the other BeanPostProcessors (ie, auto-detection in container etc).
// applied to all bean definitions before creation (including inner beans)
public interface BeanDefinitionPostProcessor
{
public BeanDefinition postProcessBeanDefinition( BeanDefinition definition, .... )
}
Some other interesting context to pass into the callback would be the bean definition registry in which the definition is contained? A flag indicating if the definition is for an inner bean or not?
An example where this could be used is in #7998. Alternativly the new @Required
annotation could be implemented as one of these? Or for cases where the context given to the callbacks in InstantiationAwareBeanPostProcessor don't suffice.
Affects: 2.0.3