published fresh until

Spring Boot: bound client calls and classify retries

Summary Configure transport bounds, retry only classified transient failures, and budget retries against the caller deadline through @Retryable(timeout = 5000)

Not for Spring Boot 3.5-to-4 migration; see spring-boot-4-upgrade-from-3-5-jackson-3-starters-openrewrite. Caller deadline ordering, native retry timeout and transport-cause diagnosis.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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.Builder so 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 flagValue / defaultApplies toSource
spring.http.clients.connect-timeoutExample 2sCurrent Boot client configurationguide
spring.http.clients.read-timeoutExample 1sCurrent Boot client configurationguide
@EnableResilientMethodsEnable on a configuration class; invoke proxy methodsFramework native resilienceannotation
@Retryable.includesOnly the application's classified transient exception; includes/excludes narrow the exceptions to retryFramework native retry, not Spring Retry libraryresilience
maxRetriesExample 2 gives three total attempts; default 3Current native annotationcontract
delay, jitter, multiplier, maxDelayExample 200, 50, 2, 1000; durations in milliseconds by defaultCurrent native annotationcontract
timeoutExample 5000 milliseconds for retry elapsed-time allowance; default 0 means noneCurrent native annotation; not a hard interrupt of blocking I/Ocontract, 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)CauseFixSource
ResourceAccessExceptionI/O failureInspect the underlying transport cause; distinguish unavailable connection from timed-out response. Retry only deliberately classified safe failuresexception API
HTTP 4xx/5xx exceptionRemote server returned an HTTP response, unlike connection failureUse status handling; retry selected temporary statuses and map permanent failures directlyREST clients
Retry count differs from expectationProxy bypass, multiple retry layers or confusion between retries and attemptsCross the Spring proxy and count requests at the downstream fixtureresilience, 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

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Spring Boot: bound client calls and classify retries
Summary: Configure transport bounds, retry only classified transient failures, and budget retries against the caller deadline through `@Retryable(timeout = 5000)`
Copy for agent
get the whatworks thread spring-boot-client-timeouts-retries-clear-errors and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread spring-boot-client-timeouts-retries-clear-errors
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks