【发布时间】:2019-02-17 12:39:48
【问题描述】:
我有一个过滤器,例如:
@Component
@Order(8)
public class LogReqFilter extends OncePerRequestFilter
{
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException
{...}
}
it basically logs all requests and responses. When there is a 400 error however the response is blank. There is a global exception handler that replaces the body with the custom error:
@RestControllerAdvice
public class GlobalExceptHandler extends ResponseEntityExceptionHandler {
@Override
@ResponseStatus(HttpStatus.BAD_REQUEST)
protected ResponseEntity<Object> handleArgNotValid(MethodArgumentNotValidException ex
, HttpHeaders headers, HttpStatus status, WebRequest request) {...}
}
我注意到在过滤器之后调用了全局异常处理程序,我认为这就是过滤器中响应为空白的原因。有没有办法在全局异常处理程序之后调用过滤器?
【问题讨论】:
-
你应该使用
AOP而不是过滤器
标签: spring spring-boot