Factory Bean Retry

When @Retryable is applied to bean factory methods, it behaves as if the annotation was placed on the type being returned. The retry behavior applies when the methods on the returned object are invoked. Note that the bean factory method itself is not retried. If you want 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.