图片来源:深入剖析Spring(三)——Bean的生命周期

image.png

这张图里一个表明了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;
    }

}

image.png
这个是BeanPostProcessor所有子类,以后再来分析下。


步履不停
38 声望14 粉丝

好走的都是下坡路