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