Why is it allowed for @Retryable and @Recover to be used only within the same class? #444
-
Hello :) I am a developer using Spring-Retry. Thank you for creating such a great library like Retry. As mentioned in the issue title, could you explain why An explanation from an implementation perspective or dependency perspective would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
您好,我已经收到您的邮件,将尽快给您回复。
|
Beta Was this translation helpful? Give feedback.
-
I think the main reason for restricting Spring Retry uses AOP proxies to intercept method calls annotated with |
Beta Was this translation helpful? Give feedback.
-
See Javadoc for
The important part is:
So, it is really crucial to have a logic in the same class to make an external call as transparent for this service as possible. In the end it is not a big deal to delegate to some other service from that Thanks, @yongsk0066 , for your answer! Converting to discussion. |
Beta Was this translation helpful? Give feedback.
I think the main reason for restricting
@Retryable
and@Recover
to the same class lies in how Spring Retry implements its functionality using proxy-based AOP.Spring Retry uses AOP proxies to intercept method calls annotated with
@Retryable
and apply the retry logic. For the proxy to handle both the retry and recovery logic effectively, it is essential to have@Retryable
and@Recover
within the same class. This allows the proxy to manage both methods and delegate the recovery process to the@Recover
method when retries exhaust.If
@Recover
were allowed in a separate class, it would complicate the proxy's ability to locate and invoke the appropriate recovery method, leading to a more compl…