For code that needs to be aware about the number of attempts, or that needs to keep information between individual attempts within a retryable invocation, Spring Retry had the RetryContext abstraction, that was given as an argument to the callback invoked by RetryTemplate, and was statically accessible through RetrySynchronizationManager from within code marked with @Retryable.
No replacement for this seems to exist in Framework's support and implementing this myself isn't straightforward in all cases. Please consider adding this functionality back.
Comment From: jhoeller
We expect such custom state management to happen in a programmatic fashion: that is, in a custom stateful Retryable<?> instance given to RetryTemplate#execute. Any between-attempts state as well as the retry count should be easy enough to store in such an instance if needed. We follow that approach across the Spring portfolio projects for all retry purposes now.
As for @Retryable, this is not designed for custom state management at all. RetryContext and RetrySynchronizationManager were intentionally left out here. We generally try to avoid direct interaction with framework state in annotated methods since this breaks our common annotated method design principles and is better off in a programmatic arrangement to begin with.
If you have concrete scenarios where you are stuck implementing them against this guidance, please let us know.