在web开发中,我们经常会用到一些拦截器,比如Java Web中的filter,已经Spring MVC中的Interceptor,其能对一个请求进行前置与后置的处理。而在Spring中,可以使用BeanFactoryPostProcessor对BeanFactory进行拦截处理。
今天就来分析一下BeanFactoryPostProcessor对BeanFactory进行拦截处理的源码。
其中 BeanFactoryPostProcessor 不是环绕拦截,而是 beanFactory 初始化完成之后的拦截。其接口源码为:
public interface BeanFactoryPostProcessor {
/**
* Modify the application context's internal bean factory after its standard
* initialization. All bean definitions will have been loaded, but no beans
* will have been instantiated yet. This allows for overriding or adding
* properties even to eager-initializing beans.
* @param beanFactory the bean factory used by the application context
* @throws org.springframework.beans.BeansException in case of errors
*/
void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;
}
pos