0

I'm using spring-retry to provide retry policy for my business logic. I have Interface and the service that implements it

public interface MyInterface {
    @Retryable(maxAttempts = 5, backoff = @Backoff(value = 0L))
    void doSth() throws Exception;

    @Recover
    void recoverIfFailed(Exception e);
}

@Service
public class MyService implements MyInterface {
    public void doSth() throws Exception {
            throw new Exception();
    }

    public void recoverIfFailed(Exception e) {
        System.out.println("Recovered!");
    }
}

and in this configuration everything working fine. However I cannot understand why I mustn't move @Recovery annotation to the interface implementation like this:

@Service
public class MyService implements MyInterface {
    @Retryable(maxAttempts = 5, backoff = @Backoff(value = 0L)) // -- this is working
    public void doSth() throws Exception {
            throw new Exception();
    }

    @Recover // -- this is not working!
    public void recoverIfFailed(Exception e) {
        System.out.println("Recovered!");
    }
}

I really would like to not expose my recovery method in the interface (as it seems to be my internal logic) but I cannot due to this issue. Can anyone advise what can be an issue?

puffy.bun
  • 256
  • 1
  • 10

1 Answers1

0

I submitted an open pull request to fix this.

As a work-around, use @EnableRetry(proxyTargetClass = true).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179