springspring-aopspring-retry

How does Spring Retry work under the hood?


I'm trying to understand how the retries are implemented, I'd expect to see something like threads in the source of Spring Retry - but I don't. I'd like to know how retrying is implemented, if not as per threads.

Additionally, I didn't find an @Aspect that would wrap the method to be retried. Since AOP is a dependency of Spring Retry - I would also expect to see some AOP stuff. Where is that 'hidden'?


Solution

  • There is no threading; retries are invoked on the calling thread.

    Spring Retry can be used in two modes:

    In Imperative Mode you programmatically invoke the target code using a RetryTemplate.

    In Declarative Mode you annotate public methods with @Retryable.

    In this mode, @EnableRetry registers 2 beans RetryConfiguration (extends AbstractPointcutAdvisor) and AnnotationAwareAspectJAutoProxyCreator.

    RetryConfiguration creates an Advice (AnnotationAwareRetryOperationsInterceptor) and AnnotationClassOrMethodPointcut.

    Using these beans, Spring AOP uses the auto proxy creator to wrap beans with @Retryable annotations in a proxy with the interceptor advice.