Есть ли способ вызвать метод обработчика исключений без @enableWebMvc в Springboot - PullRequest
0 голосов
/ 24 декабря 2018

Используя обработчик исключений, я хочу вернуть новый ответ и сломать исходный обработчик response.if CustomException выбрасывается из фильтра.

Я пробовал приведенный ниже код, но метод обработчика не вызывается.

private boolean istest = true;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {

    KPICounterHelper.incrementRequestCounter(request);
    if(istest) {
        throw new CustomException("kd ex",55);
    }

    chain.doFilter(request, response);
    KPICounterHelper.incrementResponseCounter(request);


}

   //this is handler code
   @RestControllerAdvice
     public class ExceptionHandler extends ResponseEntityExceptionHandler{

@org.springframework.web.bind.annotation.ExceptionHandler(value= 
   {CustomException.class})
public CustomException handleCustom() {
    System.out.println("in handler");
    return new CustomException("kd excccc", 565);
}

      }

    //application.properties

     spring.mvc.throw-exception-if-no-handler-found=true
     spring.resources.add-mappings=fals

Я хочу выполнить код обработчика и вернуть ответ оттуда.и хотите выполнить код метода после chain.doFilter ()

...