我想在应用程序启动后调用一些代码。有没有办法处理事件:
Started SomeApp in 14.905 seconds (JVM running for 16.268)
如果另一个应用程序启动,我将尝试。我尝试使用Retryable,但在应用程序启动之前没有执行它,并抛出异常,因此应用程序退出。
@EventListener
fun handleContextRefresh(event: ContextRefreshedEvent) {
retryableInvokeConnection()
}
@Retryable(
value = [RetryableException::class, ConnectionException::class],
maxAttempts = 100000,
backoff = Backoff(delay = 5)
)
private fun retryableInvokeConnection() {
}
@Recover
private fun retryableInvokeConnectionExceptionHandler(ex: ConnectionException) {
}
也许我应该使用PostConstruct和while循环。
你不能在同一个bean中调用@Retryable
方法,它会使用重试拦截器绕过代理。将方法移动到另一个bean并注入它。
这个事件比使用@PostConstruct
更好。