What this thread does
Do first: configure spring.http.clients.connect-timeout=2s and spring.http.clients.read-timeout=1s on a Boot-managed blocking client before adding selective retries.
Short answer
As of November 2026, this recipe targets Spring Boot 4.1.2 and Framework 7.0.10; keep managed dependencies together. Retry only classified transient failures of safe operations. Transport timeouts, retry elapsed time and the caller deadline are separate bounds.
Choose / don't choose
- RestClient: choose for blocking imperative handlers; inject Boot's
RestClient.Builderso configured transport settings apply. - WebClient: choose for a reactive chain and propagate cancellation through that chain; don't block its event-loop threads.
Not for: Spring Boot migration; see spring-boot-4-upgrade-from-3-5-jackson-3-starters-openrewrite.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
spring.http.clients.connect-timeout | Example 2s | Current Boot client configuration | guide |
spring.http.clients.read-timeout | Example 1s | Current Boot client configuration | guide |
@EnableResilientMethods | Enable on a configuration class; invoke proxy methods | Framework native resilience | annotation |
@Retryable.includes | Only the application's classified transient exception; includes/excludes narrow the exceptions to retry | Framework native retry, not Spring Retry library | resilience |
maxRetries | Example 2 gives three total attempts; default 3 | Current native annotation | contract |
delay, jitter, multiplier, maxDelay | Example 200, 50, 2, 1000; durations in milliseconds by default | Current native annotation | contract |
timeout | Example 5000 milliseconds for retry elapsed-time allowance; default 0 means none | Current native annotation; not a hard interrupt of blocking I/O | contract, implementation |
Use imports from org.springframework.resilience.annotation. These budgets are illustrative configuration choices, not a service-level guarantee.
Order of operations
1. Inspect resolved dependencies with ./mvnw dependency:tree -Dincludes=org.springframework.boot:spring-boot,org.springframework:spring-web (Maven filter). Inject the builder; RestClient.create() bypasses Boot customization. 2. Classify selected temporary statuses, e.g. 502/503/504, in retrieve().onStatus(...) by throwing an application transient exception. Leave 401/403 and other business failures outside its retry allowlist. exchange() does not invoke those status handlers (REST clients). 3. Establish the caller's absolute deadline first. Allocate shorter per-attempt connect/read/pool budgets, then a retry elapsed-time allowance below the caller budget. Count all attempts and maximum backoffs; never give every retry a fresh full caller budget. 4. The native timeout checks elapsed time before retries and pending sleeps, but does not preempt the currently executing blocking call. To enforce a strict remaining caller deadline, propagate its remaining allowance into transport/cancellation and refuse a new attempt when no budget remains. This is an application requirement inferred from the retry implementation; a fixed annotation timeout alone is insufficient. 5. Translate exhausted failures in @ControllerAdvice into a safe ProblemDetail response, e.g. 502 for a generic upstream failure and 504 for an explicit upstream-timeout contract. Keep domain errors separate. Log operation, correlation ID, status and cause without upstream secrets (error responses, factory). 6. Use controlled fixtures for connection failure, delayed response, 401 and 503/503/200. Count actual transport requests; another retry layer can multiply the configured attempts.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
ResourceAccessException | I/O failure | Inspect the underlying transport cause; distinguish unavailable connection from timed-out response. Retry only deliberately classified safe failures | exception API |
| HTTP 4xx/5xx exception | Remote server returned an HTTP response, unlike connection failure | Use status handling; retry selected temporary statuses and map permanent failures directly | REST clients |
| Retry count differs from expectation | Proxy bypass, multiple retry layers or confusion between retries and attempts | Cross the Spring proxy and count requests at the downstream fixture | resilience, jan-olaveide's February 11, 2026 request |
The report requests retry count for logging and metrics; it does not establish a client defect. Older Boot documentation uses singular spring.http.client; use the prefix matching that application's documentation (older client guide).
Missing
- Not confirmed on the linked Boot client guide: the stated retry policy for safe reads, idempotent writes and payment/4xx exclusions.
- Exact connect/read exception subclasses depend on the selected HTTP transport. No universal exception-message string distinguishes them.
- The caller's deadline and transport cancellation contract are unspecified; fixed retry annotations do not promise hard cancellation.
Checked
2026-11-12; Boot 4.1.2 and Framework 7.0.10 (Boot release, Framework release); linked references, retry source and jan-olaveide report read. No Java/client commands executed.
Started from a post by @Spring, packaged by the editor. Original post