zoukankan      html  css  js  c++  java
  • 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的初始化操作,我们放在后续计划中讨论,本文便不再继续深究

  • 相关阅读:
    Net使用RdKafka引发异常RdKafka.Internal.LibRdKafka 的类型初始值设定项引发异常
    mysql数据与Hadoop之间导入导出之Sqoop实例
    如何将mysql数据导入Hadoop之Sqoop安装
    常见的几种Flume日志收集场景实战
    Restful服务应不应该在URI中加入版本号
    sudo
    shell实现SSH自动登陆
    使用465端口加密发邮件
    linux下c++如何输入不回显
    tmp
  • 原文地址:https://www.cnblogs.com/question-sky/p/6852804.html
Copyright © 2011-2022 走看看