Bean Creation Retry
As mentioned previously, @Retryable
advice is integrated right at the container level. This is useful as it is common problem in Microservices and environments like Docker where there may be a delay in services becoming available.
The following snippet is taken from the Neo4j driver support and demonstrates how bean creation can be wrapped in retry support:
@Factory (1)
public class Neo4jDriverFactory {
...
@Retryable(ServiceUnavailableException.class) (2)
@Bean(preDestroy = "close")
public Driver buildDriver() {
...
}
}
1 | A factory bean is created that defines methods that create beans |
2 | The @Retryable annotation is used to catch ServiceUnavailableException and retry creating the driver before failing startup. |