public abstract class ResponseEntityExceptionHandler extends ObjectSE
@ExceptionHandler
メソッドから @RequestMapping
メソッドまでのすべての @RequestMapping
メソッドで一元化された例外処理を提供したい @ControllerAdvice
クラスの便利な基本クラス。 この基本クラスは、内部 Spring MVC 例外を処理するための @ExceptionHandler
メソッドを提供します。このメソッドは、ModelAndView
を返す DefaultHandlerExceptionResolver
とは対照的に、message converter
でレスポンスに書き込むために ResponseEntity
を返します。
エラーコンテンツをレスポンス本文に書き込む必要がない場合、または(ContentNegotiatingViewResolver
などを介して)ビューリゾルバーを使用する場合は、DefaultHandlerExceptionResolver
で十分です。
@ControllerAdvice
サブクラスを検出するには、ExceptionHandlerExceptionResolver
を構成する必要があることに注意してください。
handleException(Exception, WebRequest)
, DefaultHandlerExceptionResolver
修飾子と型 | フィールドと説明 |
---|---|
protected Log | logger サブクラスで使用する共通のロガー。 |
static StringSE | PAGE_NOT_FOUND_LOG_CATEGORY リクエストに対してマップされたハンドラーが見つからない場合に使用するログカテゴリ。 |
protected static Log | pageNotFoundLogger リクエストに対してマッピングされたハンドラーが見つからない場合に使用する特定のロガー。 |
コンストラクターと説明 |
---|
ResponseEntityExceptionHandler() |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public static final StringSE PAGE_NOT_FOUND_LOG_CATEGORY
pageNotFoundLogger
, 定数フィールド値 protected static final Log pageNotFoundLogger
protected final Log logger
@ExceptionHandler(value={HttpRequestMethodNotSupportedException.class,HttpMediaTypeNotSupportedException.class,HttpMediaTypeNotAcceptableException.class,MissingPathVariableException.class,MissingServletRequestParameterException.class,ServletRequestBindingException.class,ConversionNotSupportedException.class,TypeMismatchException.class,HttpMessageNotReadableException.class,HttpMessageNotWritableException.class,MethodArgumentNotValidException.class,MissingServletRequestPartException.class,BindException.class,NoHandlerFoundException.class,AsyncRequestTimeoutException.class}) @Nullable public final ResponseEntity<ObjectSE> handleException(ExceptionSE ex, WebRequest request) throws ExceptionSE
ex
- ターゲット例外 request
- 現在のリクエスト ExceptionSE
protected ResponseEntity<ObjectSE> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
このメソッドは警告をログに記録し、"Allow" ヘッダーを設定し、handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.context.request.WebRequest)
に委譲します。
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
このメソッドは、"Accept" ヘッダーを設定し、デリゲートを handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.context.request.WebRequest)
に設定します。
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleMissingPathVariable(MissingPathVariableException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleServletRequestBindingException(ServletRequestBindingException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleConversionNotSupported(ConversionNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleHttpMessageNotWritable(HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleMissingServletRequestPart(MissingServletRequestPartException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス request
- 現在のリクエスト ResponseEntity
インスタンス @Nullable protected ResponseEntity<ObjectSE> handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest)
ex
- 例外 headers
- レスポンスに書き込まれるヘッダー status
- 選択したレスポンスステータス webRequest
- 現在のリクエスト ResponseEntity
インスタンス protected ResponseEntity<ObjectSE> handleExceptionInternal(ExceptionSE ex, @Nullable ObjectSE body, HttpHeaders headers, HttpStatus status, WebRequest request)
デフォルトの実装では、WebUtils.ERROR_EXCEPTION_ATTRIBUTE
リクエスト属性を設定し、指定された本文、ヘッダー、ステータスから ResponseEntity
を作成します。
ex
- 例外 body
- レスポンスの本文 headers
- レスポンスのヘッダー status
- レスポンスステータス request
- 現在のリクエスト