spring-retry

v2026.09.24

Spring Retry for transparent retry support in Spring applications. Covers @Retryable, @Recover, RetryTemplate, backoff policies, and circuit breakers. USE WHEN: user mentions "spring retry", "@Retryable", "@Recover", "RetryTemplate", "backoff policy", "retry transient failure", "automatic retry" DO NOT USE FOR: circuit breaker patterns - use `spring-cloud-circuitbreaker` skill, message retry - use `spring-kafka` or messaging skill retry topics

GitHub
Install command
npx skhub add claude-dev-suite/spring-retry
Markdown
SKILL.md

Spring Retry - Quick Reference

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

Discovery
Tags

No tags published for this skill.

Version
Latest version metadata

Version

v2026.09.24

Published

Sep 24, 2026

Category

Uncategorized

License

MIT

Source path

skills/backend-frameworks/spring-retry

Default branch

main

Latest commit

9496306

Tree SHA

fe4e2f1