InstantiationAwareBeanPostProcessor, about Spring calls its related interface before the bean object is instantiated, for example, interface:
postProcessBeforeInstantiation
about this interface, there is an explanation in the documentation:
Apply this BeanPostProcessor before the target bean gets instantiated.The returned bean object may bea proxy to use instead of the target bean,effectively suppressing default instantiation of the target bean.
means that the interface can also return proxy objects, so here comes the problem:
generally, our Aop proxy objects are generated in the postProcessAfterInitialization method of BeanPostProcessor
/**
* Create a proxy with the configured interceptors if the bean is
* identified as one to proxy by the subclass.
* @see -sharpgetAdvicesAndAdvisorsForBean
*/
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean != null) {
Object cacheKey = getCacheKey(bean.getClass(), beanName);
if (!this.earlyProxyReferences.contains(cacheKey)) {
return wrapIfNecessary(bean, beanName, cacheKey);
}
}
return bean;
}
where wrapIfNecessary is the method for generating proxy objects
ask everyone, so why the postProcessBeforeInstantiation in InstantiationAwareBeanPostProcessor may also return the proxy object? In what scenarios will there be such a need?