Cannot forward to error page for request [/wechat/portal] as the response has already been commit

6198 단어 J2EE

1. 문제 설명


최근 Spring Boot을 사용하여 웹 프레임워크를 구축하는 과정에서 이러한 문제가 발생했습니다. 이 인터페이스는 위챗 서버의 서명 검사를 받았지만 요청할 때 ERROR을 보고했습니다.
2018-05-30 13:56:14.265 ERROR - Cannot forward to error page for request 
[/wechat/portal/hdd] as the response has already been committed. As a 
result, the response may have the wrong status code. If your application 
is running on WebSphere Application Server you may be able to resolve this 
problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to 
false (o.s.boot.web.support.ErrorPageFilter:210) [http-nio-8080-exec-6]

2. 솔루션


로그 알림을 보려면 false com.ibm.ws.webcontainer.invokeFlushAfterService 를 설정해야 합니다.
    @Bean
    public ErrorPageFilter errorPageFilter() {
        return new ErrorPageFilter();
    }

    @Bean
    public FilterRegistrationBean disableSpringBootErrorFilter(ErrorPageFilter filter) {
         FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
         filterRegistrationBean.setFilter(filter);
         filterRegistrationBean.setEnabled(false);
         return filterRegistrationBean;
    }
  • 수정된 후에 재배치하면 확실히 ERROR을 보고하지 않지만 인터페이스는 404를 보고한다.
  • 이때 여러분은 자신의 Url이 정확한지 확인할 수 있습니다. 제 상황은:
  • 인터페이스 URL이 맞아요. 그리고remote debug는 들어갈 수도 있고 정상적으로 리턴할 수도 있어요. 하지만localhost_ 보기access_로그도 404가 확실합니다. 이상하다고 할 수 있습니다.

  • 3. 깊이 파고들다


    인터페이스 코드 부착:
    @GetMapping(produces = "text/plain;charset=utf-8")
        public String authGet(@RequestParam(name = "signature", required = false) String signature,
                              @RequestParam(name = "timestamp", required = false) String timestamp,
                              @RequestParam(name = "nonce", required = false) String nonce,
                              @RequestParam(name = "echostr", required = false) String echostr) {
            return authGet(signature, timestamp, nonce, echostr, null);
        }
    
        @ResponseBody
        @GetMapping(value = "/{channel}", produces = "text/plain;charset=utf-8")
        public String authGet(@RequestParam(name = "signature", required = false) String signature,
                              @RequestParam(name = "timestamp", required = false) String timestamp,
                              @RequestParam(name = "nonce", required = false) String nonce,
                              @RequestParam(name = "echostr", required = false) String echostr,
                              @PathVariable(name = "channel") String channel) {
            log.info("
    [{}, {}, {}, {},{}]"
    , signature, timestamp, nonce, echostr, channel); if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) { throw new IllegalArgumentException(" , !"); } WxMpService wxMpService = oldHxWeChatService; if (channel != null) { wxMpService = hxWeChatService; } if (wxMpService.checkSignature(timestamp, nonce, signature)) { return echostr; } return " "; }

    솔루션: response 출력 흐름 또는 @ResponseBody 사용
  • response.getWriter().print(echostr);
  • @responseBody 메모의 역할은 controller 방법으로 반환된 대상을 적당한 변환기를 통해 지정된 형식으로 변환한 후 response body JSON 데이터나 XML 데이터로 되돌려 주는 데 사용하는데, 주의해야 할 것은 이 메모를 사용한 후에 프로세서를 시도하지 않고 흐름에 직접 기록하는 것이다. 그의 효과는 response 를 통해 지정된 형식의 데이터를 출력하는 것과 같다.
  • 따라서 이전에 직접 사용return echostrspring을 사용하면 대응하는 보기를 찾을 수 없지만 보기를 찾을 수 없고spring은 errorPage로 넘어갔지만 프로젝트에 설정이 없음errorPage으로 404.
  • 좋은 웹페이지 즐겨찾기