Spring源码情操陶冶-AbstractApplicationContext#postProcessBeanFactory

阅读源码有利于陶冶情操,承接前文Spring源码情操陶冶-AbstractApplicationContext#prepareBeanFactory
约定:web.xml中配置的contextClassXmlWebApplicationContext

瞧瞧官方注释

/**
     * 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 registering special
     * BeanPostProcessors etc in certain ApplicationContext implementations.
     * @param beanFactory the bean factory used by the application context
     */

主要承接前文中的prepareBeanFactory()方法后,供子类在标准的基础上再添加自定义的属性性质,主要是注册BeanPostProcessors

源码简析

对应的父类AbstractRefreshableWebApplicationContext#postProcessBeanFactory代码清单如下

    /**
     *注册request/session环境
     * 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环境,包括request、session、golableSession、application
        WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, this.servletContext);
        //注册servletContext、contextParamters、contextAttributes  、servletConfig单例bean
        WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, this.servletContext, this.servletConfig);
    }

具体的调用BeanFactoryPostProcessors可见下节

下节预告

Spring源码情操陶冶-AbstractApplicationContext#invokeBeanFactoryPostProcessors

转载于:https://www.cnblogs.com/question-sky/p/6760811.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值