クラス ResponseEntityExceptionHandler
- 実装されているすべてのインターフェース:
Aware, MessageSourceAware
ResponseEntity を返すことで、発生したすべての Spring または WebFlux 例外を処理する @ExceptionHandler メソッドを持つクラス。 アプリケーションでのグローバルな例外処理のための @ControllerAdvice の基本クラスとして便利です。サブクラスは、特定の例外を処理する個々のメソッドをオーバーライドしたり、handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange) をオーバーライドしてすべての例外の共通処理をオーバーライドしたり、createResponseEntity(Object, HttpHeaders, HttpStatusCode, ServerWebExchange) をオーバーライドして、選択した HTTP ステータスコード、ヘッダー、本文から ResponseEntity を作成する最終ステップをインターセプトしたりできます。
- 導入:
- 6.0
- 作成者:
- Rossen Stoyanchev
フィールドのサマリー
フィールドコンストラクターの概要
コンストラクター方法の概要
修飾子と型メソッド説明protected ProblemDetailcreateProblemDetail(ExceptionSE ex, HttpStatusCode status, StringSE defaultDetail, @Nullable StringSE detailMessageCode, ObjectSE @Nullable [] detailMessageArguments, ServerWebExchange exchange) protected Mono<ResponseEntity<ObjectSE>> createResponseEntity(@Nullable ObjectSE body, @Nullable HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) 指定された本文、ヘッダー、statusCode から使用するResponseEntityを作成します。protected @Nullable MessageSourceこの例外ハンドラーが使用するMessageSourceを取得します。protected Mono<ResponseEntity<ObjectSE>> handleErrorResponseException(ErrorResponseException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ErrorResponseExceptionの処理をカスタマイズします。final Mono<ResponseEntity<ObjectSE>> handleException(ExceptionSE ex, ServerWebExchange exchange) リクエストの Spring または WebFlux 処理内で発生したすべての例外を処理します。protected Mono<ResponseEntity<ObjectSE>> handleExceptionInternal(ExceptionSE ex, @Nullable ObjectSE body, @Nullable HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) 共通の処理とResponseEntityの作成のために、このクラスの他のすべてが委譲する内部ハンドラーメソッド。protected Mono<ResponseEntity<ObjectSE>> handleHandlerMethodValidationException(HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) HandlerMethodValidationExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleMethodNotAllowedException(MethodNotAllowedException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) MethodNotAllowedExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleMethodValidationException(MethodValidationException ex, HttpStatus status, ServerWebExchange exchange) MethodValidationExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleMissingRequestValueException(MissingRequestValueException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) MissingRequestValueExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleNotAcceptableStatusException(NotAcceptableStatusException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) NotAcceptableStatusExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleResponseStatusException(ResponseStatusException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ResponseStatusExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleServerErrorException(ServerErrorException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ServerErrorExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleServerWebInputException(ServerWebInputException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ServerWebInputExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleUnsatisfiedRequestParameterException(UnsatisfiedRequestParameterException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) UnsatisfiedRequestParameterExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleUnsupportedMediaTypeStatusException(UnsupportedMediaTypeStatusException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) UnsupportedMediaTypeStatusExceptionの処理をカスタマイズします。protected Mono<ResponseEntity<ObjectSE>> handleWebExchangeBindException(WebExchangeBindException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) WebExchangeBindExceptionの処理をカスタマイズします。voidsetMessageSource(MessageSource messageSource) このオブジェクトが実行されるMessageSourceを設定します。
フィールドの詳細
logger
protected final org.apache.commons.logging.Log loggerサブクラスで使用する共通のロガー。
コンストラクターの詳細
ResponseEntityExceptionHandler
public ResponseEntityExceptionHandler()
メソッドの詳細
setMessageSource
インターフェースからコピーされた説明:MessageSourceAwareこのオブジェクトが実行されるMessageSourceを設定します。通常の Bean プロパティの設定後、InitializingBean の afterPropertiesSet などの init コールバックやカスタム init メソッドの前に呼び出されます。ApplicationContextAware の setApplicationContext の前に呼び出されます。
- 次で指定:
- インターフェース
MessageSourceAwareのsetMessageSource - パラメーター:
messageSource- このオブジェクトが使用するメッセージソース
getMessageSource
handleException
@ExceptionHandler({MethodNotAllowedException.class,NotAcceptableStatusException.class,UnsupportedMediaTypeStatusException.class,MissingRequestValueException.class,UnsatisfiedRequestParameterException.class,WebExchangeBindException.class,HandlerMethodValidationException.class,ServerWebInputException.class,ServerErrorException.class,ResponseStatusException.class,ErrorResponseException.class,MethodValidationException.class}) public final Mono<ResponseEntity<ObjectSE>> handleException(ExceptionSE ex, ServerWebExchange exchange) リクエストの Spring または WebFlux 処理内で発生したすべての例外を処理します。- パラメーター:
ex- 処理する例外exchange- 現在のリクエストレスポンス
handleMethodNotAllowedException
protected Mono<ResponseEntity<ObjectSE>> handleMethodNotAllowedException(MethodNotAllowedException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) MethodNotAllowedExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleNotAcceptableStatusException
protected Mono<ResponseEntity<ObjectSE>> handleNotAcceptableStatusException(NotAcceptableStatusException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) NotAcceptableStatusExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleUnsupportedMediaTypeStatusException
protected Mono<ResponseEntity<ObjectSE>> handleUnsupportedMediaTypeStatusException(UnsupportedMediaTypeStatusException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) UnsupportedMediaTypeStatusExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleMissingRequestValueException
protected Mono<ResponseEntity<ObjectSE>> handleMissingRequestValueException(MissingRequestValueException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) MissingRequestValueExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleUnsatisfiedRequestParameterException
protected Mono<ResponseEntity<ObjectSE>> handleUnsatisfiedRequestParameterException(UnsatisfiedRequestParameterException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) UnsatisfiedRequestParameterExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleWebExchangeBindException
protected Mono<ResponseEntity<ObjectSE>> handleWebExchangeBindException(WebExchangeBindException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) WebExchangeBindExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleHandlerMethodValidationException
protected Mono<ResponseEntity<ObjectSE>> handleHandlerMethodValidationException(HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) HandlerMethodValidationExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono - 導入:
- 6.1
handleServerWebInputException
protected Mono<ResponseEntity<ObjectSE>> handleServerWebInputException(ServerWebInputException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ServerWebInputExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleResponseStatusException
protected Mono<ResponseEntity<ObjectSE>> handleResponseStatusException(ResponseStatusException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ResponseStatusExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleServerErrorException
protected Mono<ResponseEntity<ObjectSE>> handleServerErrorException(ServerErrorException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ServerErrorExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleErrorResponseException
protected Mono<ResponseEntity<ObjectSE>> handleErrorResponseException(ErrorResponseException ex, HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) ErrorResponseExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外headers- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
handleMethodValidationException
protected Mono<ResponseEntity<ObjectSE>> handleMethodValidationException(MethodValidationException ex, HttpStatus status, ServerWebExchange exchange) MethodValidationExceptionの処理をカスタマイズします。このメソッドは
handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatusCode, ServerWebExchange)に委譲します。- パラメーター:
ex- 処理する例外status- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono - 導入:
- 6.1
createProblemDetail
protected ProblemDetail createProblemDetail(ExceptionSE ex, HttpStatusCode status, StringSE defaultDetail, @Nullable StringSE detailMessageCode, ObjectSE @Nullable [] detailMessageArguments, ServerWebExchange exchange) - パラメーター:
ex- 処理中の例外status- 例外に関連付けるステータスdefaultDetail- 「詳細」フィールドのデフォルト値detailMessageCode-MessageSourceを通じて「詳細」フィールドを検索するために使用するコード。nullの場合、使用するデフォルトのメッセージコードを決定するためにErrorResponse.getDefaultDetailMessageCode(Class, String)が使用されます。detailMessageArguments- detailMessageCode の議論- 戻り値:
- 作成された
ProblemDetailインスタンス
handleExceptionInternal
protected Mono<ResponseEntity<ObjectSE>> handleExceptionInternal(ExceptionSE ex, @Nullable ObjectSE body, @Nullable HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) 共通の処理とResponseEntityの作成のために、このクラスの他のすべてが委譲する内部ハンドラーメソッド。デフォルトの実装では、次のことが行われます。
- レスポンスがすでにコミットされている場合は
nullを返す - レスポンスステータスが 500 (INTERNAL_SERVER_ERROR) の場合は、
"jakarta.servlet.error.exception"リクエスト属性を設定します。 bodyがnullの場合、ErrorResponse例外からbodyを抽出します。
- パラメーター:
ex- 処理する例外body- レスポンスに使用するボディheaders- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- レスポンス用の
ResponseEntityを含むMono
- レスポンスがすでにコミットされている場合は
createResponseEntity
protected Mono<ResponseEntity<ObjectSE>> createResponseEntity(@Nullable ObjectSE body, @Nullable HttpHeaders headers, HttpStatusCode status, ServerWebExchange exchange) 指定された本文、ヘッダー、statusCode から使用するResponseEntityを作成します。サブクラスはこのメソッドをオーバーライドして、本文、ヘッダー、statusCode をインスペクションし、必要に応じて変更して、たとえば、ProblemDetailのインスタンスをProblemDetailの拡張として再作成することができます。- パラメーター:
body- レスポンスに使用するボディheaders- レスポンスに使用するヘッダーstatus- レスポンスに使用するステータスコードexchange- 現在のリクエストとレスポンス- 戻り値:
- 作成された
ResponseEntityを持つMono - 導入:
- 6.0