Spring container?-Related extension points

// 如果容器内的bean实现了该接口,那么在容器中实例化任何其他bean之前都会回调该方法来对bean的配置元数据进行修改
public interface BeanFactoryPostProcessor {
    void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;
}
// 通知接口
public interface Aware {

}

// 常用:
// - BeanNameAware
// - BeanFactoryAware
// - BeanClassLoaderAware
// - ApplicationContextAware
// 如果容器内的bean实现了该接口,那么在容器实例化该bean之后,执行初始化方法前/后调用
public interface BeanPostProcessor {
    // call before initMethod
    default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    // call after initMethod
    default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
// 如果bean实现了该接口,那么容器会在实例化完成后调用afterPropertiesSet方法进行一些初始化
public interface InitializingBean {
    void afterPropertiesSet() throws Exception;
}
// 如果bean实现了该接口,容器会在bean实例销毁之前调用destory方法,来完成一些回收工作
public interface DisposableBean {
    void destroy() throws Exception;
}

Reference: https://www.cnblogs.com/v1haoge/p/6106456.html

Guess you like

Origin www.cnblogs.com/jieyuefeng/p/11701554.html