2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring BootのExceptionHandlerでExceptionがthrowされたControllerのMethodが知りたい

Last updated at Posted at 2018-12-15

1. やりたいこと

  • ExceptionHandlerで例外処理を設定する
  • どのControllerのどのMethodで例外が発生したかを知る

2. バージョンや条件など

  • Java 11
  • Spring Boot 2.1.1.RELEASE

3. やったこと

  • ExceptionHandlerアノテーションを付けたメソッドのパラメータにHandlerMethod handlerMethodを追加する
MyExceptionHandler.java

@ExceptionHandler(MyException.class)
public ResponseEntity<String> myExceptionHandler(
    MyException exception,
    HandlerMethod handlerMethod) {

    // 省略
}
  • HandlerMethodについては Javadoc を参照
  • getMethod()getMethodAnnotation(java.lang.Class<A> annotationType)が使えそう

4. ドキュメント

おわり。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?