The general process of springMvc source code

web.xml loads DispatcherServlet (the subclass has both its own features and all the features of the parent class. If there is an override method with the subclass's own, a method of the parent class has an entry function.

Then if you use a subclass (the subclass overrides this method), this method of the subclass will also have an entry feature)

 

source distribution entry

 

DispatcherServlet--"Application Context Initialization--"Execute Forwarding--"Through Various Interceptors--"Final Jump

 

FrameworkServlet

  public void onApplicationEvent(ContextRefreshedEvent event)

  {

    this.refreshEventReceived = true;

    onRefresh(event.getApplicationContext());

  }

  

  protected void onRefresh(ApplicationContext context) {}///When the framework writes an interface, it will first write an abstract one for itself to call. When a subclass inherits it later, this method will be overridden in the subclass

  call this specific method

  

 

 

  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);

    }

  }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326442695&siteId=291194637