Factory Bean Retry

When @Retryable is applied to bean factory methods, it will behave as if the annotation was placed on the type being returned. When the methods on the returned object get invoked, the retry behavior will apply at that time. Note that the bean factory method itself will not be retried. If you would like the functionality of creating the bean to be retried, it should be delegated to another singleton that has the @Retryable annotation applied.

For example:

  1. @Factory (1)
  2. public class Neo4jDriverFactory {
  3. ...
  4. @Retryable(ServiceUnavailableException.class) (2)
  5. @Bean(preDestroy = "close")
  6. public Driver buildDriver() {
  7. ...
  8. }
  9. }
1A factory bean is created that defines methods that create beans
2The @Retryable annotation is used to catch exceptions thrown from methods executed on the Driver.