0

I would like to invoke some code after my application start. Is there any way to handle event:

Started SomeApp in 14.905 seconds (JVM running for 16.268) 

I'm going to try if another application is up. I've tried to use Retryable but not its executed before application started and exception is thrown so application exits.

    @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) {
    }

Maybe I should use PostConstruct and while loop.

MrNetroful
  • 497
  • 8
  • 28

1 Answers1

1

You can't call a @Retryable method within the same bean, it bypasses the proxy with the retry interceptor. Move the method to another bean and inject it.

The event is a better way than using @PostConstruct.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179