图片起源:深刻分析 Spring(三)——Bean 的生命周期
这张图里一个表明了 bean 的生命周期,另外一个也阐明了 BeanPostProcessor 在设置了 bean 的属性后的前置解决与后置解决。
这个是 BeanPostProcessor 的定义:
/**
* Factory hook that allows for custom modification of new bean instances —
* for example, checking for marker interfaces or wrapping beans with proxies.
*
* <p>Typically, post-processors that populate beans via marker interfaces
* or the like will implement {@link #postProcessBeforeInitialization},
* while post-processors that wrap beans with proxies will normally
* implement {@link #postProcessAfterInitialization}.
*
*/
public interface BeanPostProcessor {
@Nullable
default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {return bean;}
@Nullable
default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {return bean;}
}
这个是 BeanPostProcessor 所有子类,当前再来剖析下。