続行する前に、サービス層の特定の属性について HttpServletRequest を検証する必要があります。@Before アドバイスを作成しましたが、AOP メソッドが例外をスローすることに注意してください。このメソッドによってスローされた例外は、RestControllerAdvice によって処理される必要があります。AOP メソッドが実行されていることがわかりますが、DataNotValidException は RestControllerAdvice によって処理されていません。RestConrollerAdvice は、他のパラメーターの検証に例外がある場合、または RestController に例外がある場合、正常に機能しています。
@Before("execution(* com.mycom.service.app.myappName.handler*.*.*(..)) && args(httpServletRequest,..)" )
public void validateRequest(JoinPoint joinPoint, HttpServletRequest httpServletRequest) throws DataNotValidException {
これは私の @RestControllerAdvice です。handleExceptionInternal もオーバーライドしようとしました。
public String handleLinkage(final HttpServletRequest httpServletRequest, @Valid UserLinkRequest userLinkReqeust, final 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
} }