4

I have a spring managed bean of type B. I have @EnableREtry in a @Configuration class. When I use @Retryable on doStuff(), the method gets retried on failure as expected.

But, the method I really want to retry is a method defined in the base class, A. A is a concrete class and not a spring managed bean. the doSomethingElse method doesn't get retried on throwing an exception.

I really want doSomethingElse to be retried, the base class method. However, I'm not sure how to do this. I'm guessing it's because A is a concrete class and not a bean, although it does serve as a base class.

Do I need to use a RetryableTemplate in class A?

public class B extends A {

   public void doStuff() {
      super.doSomethingElse();
   }
}

public class A {
     // doesn't actually retry
    @Retryable
    public void doSomething() {
      throws new Exception();
    }
}

1 Answer 1

25

@Retryable is implemented using Spring AOP.

Only external calls to retryable methods go through the proxy (which invokes the method within a RetryTemplate); internal calls within the class bypass the proxy and therefore are not retried.

You can play some tricks to get a reference to the proxy from the application context and call that, or simply use a RetryTemplate directly within your doStuff() method.

1
  • I believe RetryTemplate would be useful here since it would operate on classes that aren't managed by spring (at least, I assume so). Jan 25, 2017 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.