Spring源码情操陶冶-AbstractApplicationContext#finishRefresh

承接前文Spring源码情操陶冶-AbstractApplicationContext#finishBeanFactoryInitialization
约定web.xml配置的contextClass为默认值XmlWebApplicationContext

直接源码AbstractApplicationContext#finishRefresh

    /**
     * Finish the refresh of this context, invoking the LifecycleProcessor's
     * onRefresh() method and publishing the
     * {@link org.springframework.context.event.ContextRefreshedEvent}.
     */
    protected void finishRefresh() {
        // Initialize lifecycle processor for this context.
        //会找寻lifecycleProcessor对应的bean,否则默认采用DefaultLifecycleProcessor
        initLifecycleProcessor();

        // Propagate refresh to lifecycle processor first.
        getLifecycleProcessor().onRefresh();

        // Publish the final event.
        //其实是执行ContextRefreshedEvent该事件是针对spring mvc来的
        publishEvent(new ContextRefreshedEvent(this));

        // Participate in LiveBeansView MBean, if active.
        LiveBeansView.registerApplicationContext(this);
    }

从注释上可以得知其是完成对context的刷新,并执行LifecycleProcessor的onRefresh()方法和执行相关的ContextRefreshedEvent事件,但可惜引导DispatcherServlet进行初始化的ContextRefreshListener并不是由spring来触发的,而是由tomcat加载web.xml中的spring mvc配置文件启动的

DispatcherServlet#initStrategies

我们简单看下此段代码,spring启动只会帮助springmvc先初始化默认的策略方案,其他则由springmvc本身来执行,具体如下

    /**
     * Initialize the strategy objects that this servlet uses.
     * <p>May be overridden in subclasses in order to initialize further strategy objects.
     */
    protected void initStrategies(ApplicationContext context) {
        initMultipartResolver(context);
        initLocaleResolver(context);
        initThemeResolver(context);
        initHandlerMappings(context);
        initHandlerAdapters(context);
        initHandlerExceptionResolvers(context);
        initRequestToViewNameTranslator(context);
        initViewResolvers(context);
        initFlashMapManager(context);
    }

关于spring mvc的初始化操作,我们放在后续计划中讨论,本文便不再继续深究

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值