I would like to create a @Bean of a third party service like Keycloak (or any other) which may or may not be reachable at any given time. This object should retry all methods of the resulting Keycloak bean.
I have tried the following:
@Configuration
@EnableRetry
class KeycloakBeanProvider() {
@Bean
@Retryable
fun keycloak(oauth2ClientRegistration: ClientRegistration): Keycloak {
return KeycloakBuilder.builder()
.serverUrl(serverUrl)
.realm(oauth2ClientRegistration.clientName)
.grantType(OAuth2Constants.CLIENT_CREDENTIALS)
.clientId(oauth2ClientRegistration.clientId)
.clientSecret(oauth2ClientRegistration.clientSecret)
.build()
}
}
But this way only the bean creation will be retried, not actual method calls on the bean. I know @Retryable can be used on class level but I don't own the Keycloak class so I can't add it there.
How can I make the methods of the resulting Keycloak bean retryable?