springMvc源码大致过程

web.xml加载DispatcherServlet(子类兼有自己特性还有父类所有的特性,若有覆盖方法的用子类自己的,父类的某个方法有入口作用

那么如果用子类的话(子类 覆盖了这个方法)子类的这个方法也就有了入口特性)

 

源配入口

 

DispatcherServlet--》应用上下文初始化--》执行转发--》通过各种拦截器--》最终跳转

 

FrameworkServlet

  public void onApplicationEvent(ContextRefreshedEvent event)

  {

    this.refreshEventReceived = true;

    onRefresh(event.getApplicationContext());

  }

  

  protected void onRefresh(ApplicationContext context) {}///框架在写接口时会自己先写一个抽象的供自己调用,后面有子类继承他的时候覆写这个方法就会在子类中

  调用这个具体方法了

  

 

 

  DispatcherServlet

 

 protected void onRefresh(ApplicationContext context)

  {

    initStrategies(context);

  }

 

  protected void initStrategies(ApplicationContext context)

  {

    initMultipartResolver(context);

    initLocaleResolver(context);

    initThemeResolver(context);

    initHandlerMappings(context);

    initHandlerAdapters(context);

    initHandlerExceptionResolvers(context);

    initRequestToViewNameTranslator(context);

    initViewResolvers(context);

    initFlashMapManager(context);

  }

 

 

 

 

 

protected void doService(HttpServletRequest request, HttpServletResponse response)

    throws Exception

  {

  

  

    doDispatch(request, response);

 

 

  }

 

 protected void doDispatch(HttpServletRequest request, HttpServletResponse response)

    throws Exception

  {

 mappedHandler.applyPostHandle(processedRequest, response, mv);

 processDispatchResult(processedRequest, response, mappedHandler, mv, dispatchException);

 

}

 

 

 

  private void processDispatchResult(HttpServletRequest request, HttpServletResponse response, HandlerExecutionChain mappedHandler, ModelAndView mv, Exception exception)

    throws Exception

  {

    boolean errorView = false;

    if (exception != null) {

      if ((exception instanceof ModelAndViewDefiningException))

      {

        this.logger.debug("ModelAndViewDefiningException encountered", exception);

        mv = ((ModelAndViewDefiningException)exception).getModelAndView();

      }

      else

      {

        Object handler = mappedHandler != null ? mappedHandler.getHandler() : null;

        mv = processHandlerException(request, response, handler, exception);

        errorView = mv != null;

      }

    }

    if ((mv != null) && (!mv.wasCleared()))

    {

      render(mv, request, response);

      if (errorView) {

        WebUtils.clearErrorRequestAttributes(request);

      }

    }

    else if (this.logger.isDebugEnabled())

    {

      this.logger.debug("Null ModelAndView returned to DispatcherServlet with name '" + getServletName() + "': assuming HandlerAdapter completed request handling");

    }

    if (WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {

      return;

    }

    if (mappedHandler != null) {

      mappedHandler.triggerAfterCompletion(request, response, null);

    }

  }

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值