0

在继续之前,我需要验证服务层中某些属性的 HttpServletRequest。我创建了@Before 建议,请注意 AOP 方法会抛出异常。我希望这个方法抛出的异常应该由 RestControllerAdvice 处理。我可以看到正在执行 AOP 方法,但 RestControllerAdvice 没有处理 DataNotValidException。如果其他参数的验证有任何异常或 RestController 中有任何异常,RestConrollerAdvice 工作正常。

@Before("execution(* com.mycom.service.app.myappName.handler*.*.*(..)) && args(httpServletRequest,..)" )
public void validateRequest(JoinPoint joinPoint, HttpServletRequest httpServletRequest) throws DataNotValidException {

这是我的@RestControllerAdvice。我也尝试覆盖 handleExceptionInternal 。

公共字符串句柄链接(最终 HttpServletRequest httpServletRequest,@Valid UserLinkRequest userLinkReqeust,最终 HttpHeaders httpHeaders){

    @RestControllerAdvice
    @Slf4j
    public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {

        @ExceptionHandler(value = { InvalidFormatException.class, DataNotValidException.class, Exception.class,
                SQLException.class })
        private ResponseEntity<ResponseObjectData> handleAllException(Exception exception, HttpHeaders headers,
                WebRequest request, HandlerMethod handlerMethod) {
           // logErrorNBuildResponse
        }
    @Override
    protected ResponseEntity<Object> handleExceptionInternal(
            Exception ex, @Nullable Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
        // logErrorNBuildResponse
     } }
4

0 回答 0