home wiki.fukuchiharuki.me
Menu

#author("2022-08-30T03:16:59+00:00","default:haruki","haruki")
#author("2022-09-17T03:56:22+00:00","default:haruki","haruki")
* キーワード [#j3b2be59]
- リトライ
- Kotlin
- spring-retry

* したいこと [#ee51f771]

Kotlinでspring-retryを使ってリトライ処理したい(ができない、を解決)。

* どうやって [#b42d14e2]

 @Component
 @EnableRetry
 class SomeComponent {
   @Retryable(value = [UserException::class])
   @Throws(UserException::class) // ポイント
     @Retryable(value = [UserException::class])
     @Throws(UserException::class) // ポイント
   fun doSomething(param: UserParam) { ... }
 
   @Recover
   fun recover(e: UserException, param: UserParam) { ... }
     @Recover
     fun recover(e: UserException, param: UserParam) { ... }
 }

* ちなみに [#i8b272cb]

Kotlinでは@ThrowsをつけないとUndeclaredThrowableExceptionで片付けられてしまう。

 Cannot locate recovery method; nested exception is java.lang.reflect.UndeclaredThrowableException

* 参考 [#i817a9d6]
- [[Kotlinで期待していない例外UndeclaredThrowableExceptionがやってくる - もなかアイスの試食品:https://monakaice88.hatenablog.com/entry/2020/01/31/230000]]