为什么SpringMVC4.2.5在运行RequestMappingHandlerAdapter

时间:2016-03-21 01:37:28

标签: java spring spring-mvc

我确信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必须是第二次调用的结果,对吧?

1 个答案:

答案 0 :(得分:0)

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