Feign 的默认超时是多少?超时之后会重试吗?POST 会不会被重复提交?404 怎么变成返回值而不是异常?这篇在 Spring Boot 4.0.8、Spring Cloud OpenFeign 5.0.3 上用一个会睡觉、会返回 503 和 404 的后端逐项实测并统计后端收到的请求数。
不配任何超时,GET /slow?ms=3000:后端收到 1 次请求,调用方耗时 3.1 秒 → OK slow-done read-timeout=1000(毫秒),GET /slow?ms=3000:后端收到 1 次请求,调用方耗时 1.0 秒 → EX feign.RetryableException (cause SocketTimeoutException): Read timed out executing GET http://127.0.0.1:65429/slow?ms=3000 default.read-timeout=1000 但 orders.read-timeout=5000,GET /slow?ms=3000:后端收到 1 次请求,调用方耗时 3.1 秒 → OK slow-done
client.config 下的 read-timeout 毫秒;按客户端名覆盖 default;超时异常是 RetryableException。
默认 Retryer,读超时,GET:后端收到 1 次请求,调用方耗时 1.0 秒 → EX feign.RetryableException (cause SocketTimeoutException): Read timed out executing GET http://127.0.0.1:65429/slow?ms=3000 retryer=feign.Retryer$Default,读超时,GET:后端收到 5 次请求,调用方耗时 6.3 秒 → EX feign.RetryableException (cause SocketTimeoutException): Read timed out executing GET http://127.0.0.1:65429/slow?ms=3000 同上,读超时,POST:后端收到 5 次请求,调用方耗时 6.2 秒 → EX feign.RetryableException (cause SocketTimeoutException): Read timed out executing POST http://127.0.0.1:65429/slow?ms=3000 同上,503 + Retry-After: 1:后端收到 5 次请求,调用方耗时 4.0 秒 → EX feign.RetryableException (cause ServiceUnavailable): [503 Service Unavailable] during [GET] to [http://127.0.0.1:65429/status/503] [OrdersApi#status(int)]: [busy] 同上,500:后端收到 1 次请求,调用方耗时 0.0 秒 → EX FeignException$InternalServerError: [500 Internal Server Error] during [GET] to [http://127.0.0.1:65429/status/500] [OrdersApi#status(int)]: [boom] 默认 Retryer,503 + Retry-After: 1:后端收到 1 次请求,调用方耗时 0.0 秒 → EX feign.RetryableException (cause ServiceUnavailable): [503 Service Unavailable] during [GET] to [http://127.0.0.1:65429/status/503] [OrdersApi#status(int)]: [busy] 默认 Retryer,500:后端收到 1 次请求,调用方耗时 0.0 秒 → EX FeignException$InternalServerError: [500 Internal Server Error] during [GET] to [http://127.0.0.1:65429/status/500] [OrdersApi#status(int)]: [boom]
默认永不重试;Retryer$Default 对读超时的 GET、POST 和带 Retry-After 的 503 重试 5 次,500 不重试。
默认,返回类型是 Item,后端 404:后端收到 1 次请求,调用方耗时 0.0 秒 → EX FeignException$NotFound: [404 Not Found] during [GET] to [http://127.0.0.1:65429/status/404] [OrdersApi#notFound()]: [{"error":"no such order"}]
默认,返回类型是 ResponseEntity<Item>,后端 404:后端收到 1 次请求,调用方耗时 0.0 秒 → EX FeignException$NotFound: [404 Not Found] during [GET] to [http://127.0.0.1:65429/status/404] [OrdersApi#notFoundEntity()]: [{"error":"no such order"}]
dismiss404=true,返回类型是 Item:后端收到 1 次请求,调用方耗时 0.1 秒 → EX feign.codec.DecodeException (cause RestClientException): Error while extracting response for type [class demo.Main$Item] and content type [application/json]
dismiss404=true,返回类型是 ResponseEntity<Item>:后端收到 1 次请求,调用方耗时 0.0 秒 → EX feign.codec.DecodeException (cause RestClientException): Error while extracting response for type [class demo.Main$Item] and content type [application/json]
dismiss404=true,404 的响应体为空,返回类型是 Item:后端收到 1 次请求,调用方耗时 0.0 秒 → OK null
dismiss404=true,404 的响应体为空,返回类型是 ResponseEntity<Item>:后端收到 1 次请求,调用方耗时 0.0 秒 → OK <404 NOT_FOUND Not Found,[content-length:"0", content-type:"text/plain", date:"Thu, 22 Oct 2026 01:03:33 GMT", server:"BaseHTTP/0.6 Python/3.14.8"]>
自定义 ErrorDecoder(404 转成 IllegalStateException):后端收到 1 次请求,调用方耗时 0.0 秒 → EX java.lang.IllegalStateException: 订单不存在(自定义 ErrorDecoder 转换的,方法 OrdersApi#notFound())
同上,500:后端收到 1 次请求,调用方耗时 0.0 秒 → EX FeignException$InternalServerError: [500 Internal Server Error] during [GET] to [http://127.0.0.1:65429/status/500] [OrdersApi#status(int)]: [boom]404 默认抛异常;dismiss404 把响应体当返回类型解码;error-decoder 属性配置自定义解码。