Spring Retry - Quick Reference

SkillAI & models

Spring Retry for transparent retry support in Spring applications. Covers @Retryable, @Recover, RetryTemplate, backoff policies, and circuit breakers.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Spring Retry - Quick Reference skill

What this skill tells your AI

The instructions your AI receives, as published by claude-dev-suite/claude-dev-suite in skills/backend-frameworks/spring-retry/SKILL.md and read by ahel’s review.

Full Reference: See advanced.md for RetryTemplate patterns, custom retry policies, retry listeners, stateful retry, async retry, and testing.

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: spring-retry for comprehensive documentation.

Dependencies

<dependency>
    <groupId>org.springframework.retry</groupId>
    <artifactId>spring-retry</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
</dependency>

Enable Retry

@SpringBootApplication
@EnableRetry
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

@Retryable Annotation

Basic Usage

@Retryable(maxAttempts = 3)
public String callExternalApi(String endpoint) {
    return restClient.get(endpoint);
}

With Specific Exceptions

@Retryable(
    retryFor = {ServiceUnavailableException.class, TimeoutException.class},
    noRetryFor = {PaymentDeclinedException.class},
    maxAttempts = 5
)
public PaymentResult processPayment(PaymentRequest request) {
    return paymentGateway.charge(request);
}

With Backoff

@Retryable(
    maxAttempts = 4,
    backoff = @Backoff(
        delay = 1000,       // Initial delay: 1 second
        multiplier = 2,     // Exponential: 1s, 2s, 4s
        maxDelay = 10000    // Max delay: 10 seconds
    )
)
public void sendNotification(Notification notification) {
    notificationClient.send(notification);
}

@Recover
public void recoverNotification(Exception e, Notification notification) {
    log.error("Failed to send notification after retries: {}", notification.getId());
    deadLetterQueue.add(notification);
}

@Recover Method

@Service
public class UserService {

    @Retryable(retryFor = ServiceException.class, maxAttempts = 3)
    public User getUser(Long id) {
        return userClient.findById(id);
    }

    // Must have same return type
    // First parameter can be the exception
    @Recover
    public User recoverGetUser(ServiceException e, Long id) {
        log.warn("Falling back to cached user for id: {}", id);
        return userCache.get(id);
    }

    // Multiple recover methods for different exceptions
    @Recover
    public User recoverGetUserTimeout(TimeoutException e, Long id) {
        return User.unknown(id);
    }
}

Best Practices

DoDon't
Use exponential backoffFixed rapid retries
Set max attempts limitRetry indefinitely
Handle non-retryable exceptionsRetry business errors
Log retry attemptsSilent retries
Implement recovery fallbackLet retries fail silently

When NOT to Use This Skill

  • Circuit breaker - Use spring-cloud-circuitbreaker or Resilience4j
  • Message retry - Use Kafka retry topics or DLT
  • Non-idempotent operations - Ensure idempotency first
  • Business errors - Only retry transient failures

Anti-Patterns

Anti-PatternProblemSolution
Retry indefinitelyHangs foreverSet max attempts
Fixed rapid retryOverwhelms serviceUse exponential backoff
Retrying business errorsWastes resourcesUse noRetryFor
No recovery methodSilent failuresImplement @Recover

Quick Troubleshooting

ProblemDiagnosticFix
Retry not happeningCheck @EnableRetryAdd to config class
@Recover not calledCheck method signatureMatch return type and params
Too many retriesCheck maxAttemptsReduce or add timeout
Backoff not workingCheck annotationVerify @Backoff config

Production Checklist

  • Appropriate max attempts set
  • Exponential backoff configured
  • Max delay capped
  • Non-retryable exceptions defined
  • Recovery methods implemented
  • Retry listeners for monitoring
  • Metrics on retry counts

Reference Documentation

Signals

GitHub stars
33
Forks
6
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
spring-retry
Source
github.com/claude-dev-suite/claude-dev-suite