exception handling for filter in spring

后端 未结 7 885
既然无缘
既然无缘 2020-12-17 14:59

I am handling exceptions in spring using @ExceptionHandler. Any exception thrown by controller is caught using method annotated with @ExceptionHandler and action is taken ac

7条回答
  •  情话喂你
    2020-12-17 15:54

    Check the below code snippet, it works for me.

    final HttpServletResponseWrapper wrapper = new 
    HttpServletResponseWrapper((HttpServletResponse) res);    
    wrapper.sendError(HttpServletResponse.SC_UNAUTHORIZED, "");    
    res = wrapper.getResponse();
    

    If you are using this inside a filter then add a return statement else chain.doFilter(req,res) will override this.

提交回复
热议问题