源码分析
源码如下:
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
}
显然,在AbstractApplicationContext中,postProcessBeanFactory
只是定义的一个抽象方法,而继承自AbstractApplicationContext的子类可重写此实现,即对于继承的子类能够对beanFactory进行其想要的操作。
例如在AbstractRefreshableWebApplicationContext
就是其实现子类
public abstract class AbstractRefreshableWebApplicationContext extends AbstractRefreshableConfigApplicationContext
implements ConfigurableWebApplicationContext, ThemeSource {
...
/**
* Register request/session scopes, a {@link ServletContextAwareProcessor}, etc.
*/
@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
//添加ServletContextAwareProcessor处理器
beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext, this.servletConfig));
//忽略自动注入
beanFactory.ignoreDependencyInterface(ServletContextAware.class);
beanFactory.ignoreDependencyInterface(ServletConfigAware.class);
//注册web应用的scope
WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, this.servletContext);
//注册和环境有关的beans
WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, this.servletContext, this.servletConfig);
}
...
}
综上,可得出结论,此处方法为ioc为我们或者第三方提供的拓展,体现了其可拓展性;