为什么 SpringMVC4.2.5 在运行 RequestMappingHandlerAdapter 时调用两次控制器



我确定http请求只发送一次。但是当成交函数RequestMappingHandlerAdapter.handleInternal时,显然是调用两次invokeHandlerMethod。守则:

@Override
protected ModelAndView handleInternal(HttpServletRequest request,
        HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
    ModelAndView mav = null;
    checkRequest(request);
    // Execute invokeHandlerMethod in synchronized block if required.
    if (this.synchronizeOnSession) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
                mav = invokeHandlerMethod(request, response, handlerMethod);
            }
        }
    }
    mav = invokeHandlerMethod(request, response, handlerMethod);
    if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) {
        applyCacheSeconds(response, this.cacheSecondsForSessionAttributeHandlers);
    }
    else {
        prepareResponse(response);
    }
    return mav;
}

我不明白为什么在这里打电话两次invokeHandlerMethod(request, response, handlerMethod)。无论如何,mav一定是第二次调用的结果,对吧?

这绝对是一个高严重性的缺陷。看起来他们已经在这里修复了它:https://github.com/spring-projects/spring-framework/commit/a02fd7c9953b8e7f629f4d3a66a450a13341576b#diff-c10711e48b26eaecfb5aec8e59afb678

最新更新