@HttpExchange is the better choice. Everything below was run, not recalled.
A declarative REST client means you write a Java interface that describes the remote API, annotate the methods, and the framework generates the HTTP code. You never write a RestTemplate call or build a URL by hand.
Tested with: Spring Boot 4.2.0, Spring Cloud 2026.0.0 (Spring Cloud OpenFeign 5.1.0, Feign 13.17), Tomcat 11.0.27, JDK 25.0.5.1 (Temurin). The Spring Cloud 2026.0.0 BOM manages Spring Boot 4.2.0, and the other versions were read from the BOM and from maven-metadata.xml. Every output block below is a file in the companion module openfeign-demo, written by its own tests. Part of the modernized series anchored by the Spring Cloud Netflix migration guide.
Netflix Feign vs OpenFeign vs HTTP Interfaces
| Netflix Feign | Spring Cloud OpenFeign | HTTP Interface (@HttpExchange) | |
|---|---|---|---|
| Status | Dead | Maintained, feature-complete (bug fixes) | Actively developed (Spring’s direction) |
| Packages | com.netflix.feign | feign.* + org.springframework.cloud.openfeign | org.springframework.web.service |
| Extra starter | — | spring-cloud-starter-openfeign | None for the annotations; spring-boot-starter-restclient for the spring.http.serviceclient.* properties |
| Annotations | Feign-native | Spring MVC style (@GetMapping) | @GetExchange / @PostExchange |
| Load balancing | Ribbon (dead) | Spring Cloud LoadBalancer (run in this post) | Via a @LoadBalanced builder (documented, not run here) |
@HttpExchange interface so you can compare.
Setup: a handful of starters and one annotation
The module’s pom.xml declares these dependencies (the BOM import and the parent are in the same file):<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<!-- Boot 4: spring.http.serviceclient.* (base-url etc.) is applied by this module, not by starter-webmvc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-restclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- resolves service IDs such as "student-service" -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Then switch Feign on with @EnableFeignClients, which scans for @FeignClient interfaces. The class is FeignDemoApplication.java; it also carries the @ImportHttpServices line used in the last section.
package com.ankurm.feign;
import com.ankurm.feign.client.HttpStudentClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.service.registry.ImportHttpServices;
@SpringBootApplication
@EnableFeignClients // scans for @FeignClient interfaces
@ImportHttpServices(group = "students", types = HttpStudentClient.class) // the @HttpExchange alternative
public class FeignDemoApplication {
public static void main(String[] args) {
SpringApplication.run(FeignDemoApplication.class, args);
}
}
Boot 4 trap: one starter you now have to name. While building theThe demo needs no Eureka server. Instead of Eureka, the application.yml below maps the service ID@HttpExchangeclient for this post, the first call failed withIllegalArgumentException: URI with undefined scheme. Thespring.http.serviceclient.students.base-urlproperty was ignored because nothing on the classpath applied it. Addingspring-boot-starter-restclient(see the comment in the pom) fixed it;spring-boot-starter-webmvcalone does not include it.
student-service to http://localhost:18367 with the simple discovery client, so the load balancer has something to resolve. That is also why the Feign log lines in the next section show http://student-service/....
Using real Eureka instead of the simple discovery client
With Eureka, add the Eureka client starter and the same name = "student-service" resolves through the registry. This is the dependency the 2020 post used. I did not run it in this module; the working Eureka setup is in Service Discovery with Eureka in Spring Boot 3.x.
<!-- with Eureka: service names resolve via Spring Cloud LoadBalancer -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
For an external (non-Eureka) API, swap name for url = "https://api.example.com". The DecodedStudentClient in the next sections does exactly that, using a placeholder.
Going deeper
- pom.xml — the full dependency list and the
noparamsprofile - Spring Cloud OpenFeign reference documentation
- Service Discovery with Eureka in Spring Boot 3.x
The client interface: write the contract, call it like a bean
Here is the whole client, StudentClient.java. The name is a service ID, not a URL; each method is an ordinary Spring MVC mapping.package com.ankurm.feign.client;
import com.ankurm.feign.Student;
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/** The plain OpenFeign client. "student-service" is a service ID, resolved by Spring Cloud LoadBalancer. */
@FeignClient(name = "student-service")
public interface StudentClient {
@GetMapping("/api/students")
List<Student> findAll();
@GetMapping("/api/students/{id}")
Student findById(@PathVariable("id") int id); // ALWAYS name the variable
@PostMapping("/api/students")
Student create(@RequestBody Student student);
@GetMapping("/api/students/slow")
String slow(@RequestParam("ms") int ms);
}
The payload type is a one-line record, Student.java:
package com.ankurm.feign;
/** The payload shared by the fake remote service and every client. */
public record Student(int id, String name, String branch) {}
Other code injects the interface like any bean and Feign supplies the proxy. This is the service class from the 2020 post; it is not part of the repository module, so it is a download instead: EnrollmentService.java (compiled and run against the module before publishing).
package com.ankurm.feign;
import com.ankurm.feign.client.StudentClient;
import java.util.List;
import org.springframework.stereotype.Service;
/** Inject the Feign interface like any other bean; Spring Cloud OpenFeign builds the proxy behind it. */
@Service
public class EnrollmentService {
private final StudentClient studentClient;
public EnrollmentService(StudentClient studentClient) {
this.studentClient = studentClient; // inject the interface; Feign builds the proxy
}
public List<Student> activeStudents() {
return studentClient.findAll();
}
}
Calling the three methods against a real server produced the output below, from 01-happy-path.txt. The log lines are Feign’s own, enabled by logger-level: basic plus a DEBUG level for the interface. Millisecond figures drift from run to run.
findAll() -> [Student[id=1, name=Asha, branch=CS], Student[id=2, name=Ravi, branch=IT], Student[id=3, name=Meera, branch=EXTC]]
findById(2) -> Student[id=2, name=Student-2, branch=CS]
create(Kiran, ME) -> Student[id=100, name=Kiran, branch=ME]
Feign's own log (logger-level: basic):
[StudentClient#findAll] ---> GET http://student-service/api/students HTTP/1.1
[StudentClient#findAll] <--- HTTP/1.1 200 (138ms)
[StudentClient#findById] ---> GET http://student-service/api/students/2 HTTP/1.1
[StudentClient#findById] <--- HTTP/1.1 200 (7ms)
[StudentClient#create] ---> POST http://student-service/api/students HTTP/1.1
[StudentClient#create] <--- HTTP/1.1 201 (6ms)
Read the log for what Feign did: it logged the outgoing request with the service ID in the URL, then the status and elapsed time. That one line per call is the cheapest debugging aid you get, and the next sections lean on it.
Going deeper
- RemoteStudentController.java — the fake downstream service every client in this module calls
- HappyPathTest.java — the test that wrote the transcript above
- UnnamedPathVariableClient.java — the client that breaks the always name the variable rule (see Pitfalls)
Timeouts: the property prefix that silently does nothing
Timeouts are configuration, not code. The module’s defaults live in application.yml: a 2-second connect timeout for every client, and a log level.server:
port: 18367
demo:
remote-url: http://localhost:18367
spring:
application:
name: openfeign-demo
cloud:
discovery:
client:
simple:
instances:
student-service:
- uri: http://localhost:18367 # stands in for Eureka: "student-service" -> this URI
openfeign:
client:
config:
default: # applies to every client
connect-timeout: 2000
logger-level: basic
http:
serviceclient:
students:
base-url: http://localhost:18367
logging:
level:
com.ankurm.feign.client.StudentClient: DEBUG # Feign logs under the interface name
A per-client override goes under the client’s name. application-newprefix.yml gives student-service a 1-second read timeout:
spring:
cloud:
openfeign:
client:
config:
student-service: # per-client override
read-timeout: 1000
The 2020-era tutorials used a different prefix, feign.client.config.*. application-oldprefix.yml sets the same 1-second read timeout under that old prefix:
# The 2020-era prefix. It does not bind on current releases.
feign:
client:
config:
student-service:
read-timeout: 1000
I ran the same call against a server that sleeps 3 seconds under each profile (TimeoutNewPrefixTest.java and TimeoutOldPrefixTest.java). Transcripts: 03-timeout-newprefix.txt and 04-timeout-oldprefix.txt.
profile : newprefix
server sleeps: 3000 ms, read-timeout configured: 1000 ms
outcome : threw feign.RetryableException -> Read timed out executing GET http://student-service/api/students/slow?ms=3000
took : about 1000 ms (gave up at the timeout)
profile : oldprefix
server sleeps: 3000 ms, read-timeout configured: 1000 ms
outcome : returned: answered after 3000 ms
took : about 3000 ms (waited for the full answer)
The two runs differ only by the prefix. With spring.cloud.openfeign.client.config the call gave up at one second with a RetryableException wrapping a read timeout. With the old feign.client.config the setting was ignored and the call simply waited for the full answer. No error, no warning.
This is the most common silent misconfiguration in migrated projects. The 2020 version of this post said an unbound timeout means “infinite defaults”. That was too strong: what I measured is that the call waited the full 3 seconds. I did not measure how long it would wait for a slower server, so treat the real default as a number to look up rather than as “infinite”. If a timeout “does not work”, check the prefix first.
Going deeper
- TimeoutOldPrefixTest.java — the assertion that the old prefix is ignored
- OpenFeign reference: configuration properties
Errors: one exception type until you decode it yourself
Feign throws aFeignException for every non-2xx response, with a subclass per status. The first call below uses the plain client from above; the second uses DecodedStudentClient.java, which plugs in a custom ErrorDecoder through DomainErrorConfig.java.
package com.ankurm.feign.client;
import feign.Response;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
/** Per-client configuration. Deliberately NOT annotated @Configuration (see the pitfalls in the post). */
public class DomainErrorConfig {
@Bean
ErrorDecoder domainErrorDecoder() {
ErrorDecoder fallbackToDefault = new ErrorDecoder.Default();
return (methodKey, response) -> {
if (response.status() == 404) {
return new StudentNotFoundException("404 from " + methodKey + " (" + response.request().url() + ")");
}
return fallbackToDefault.decode(methodKey, response);
};
}
}
package com.ankurm.feign.client;
import com.ankurm.feign.Student;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/** Same call as StudentClient, but with a custom ErrorDecoder and a fixed URL instead of a service ID. */
@FeignClient(name = "decoded", url = "${demo.remote-url}", configuration = DomainErrorConfig.class)
public interface DecodedStudentClient {
@GetMapping("/api/students/{id}")
Student findById(@PathVariable("id") int id);
}
Both clients called findById(99), which the fake server answers with a 404. Transcript: 02-error-handling.txt.
StudentClient.findById(99) [default decoder]
exception : feign.FeignException$NotFound
status : 404
message : [404] during [GET] to [http://student-service/api/students/99] [StudentClient#findById(int)]: [{"detail":"No student with id 99","status":404,"title":"Not Found"}]
DecodedStudentClient.findById(99) [custom ErrorDecoder]
exception : com.ankurm.feign.client.StudentNotFoundException
message : 404 from DecodedStudentClient#findById(int) (http://localhost:18367/api/students/99)
DecodedStudentClient.findById(503) [custom decoder delegates non-404 to the default]
exception : feign.FeignException$ServiceUnavailable
status : 503
The default client surfaces FeignException$NotFound with the response body folded into the message. The custom decoder turns the same 404 into a domain exception your service code can catch by meaning rather than by status number, and anything it does not recognise (the third call, a 503) falls through to Feign’s default, so only the cases you chose change.
Keep the decoder class out of component scanning.DomainErrorConfigis deliberately not annotated@Configuration, and it is referenced throughconfiguration =on one client. The Spring Cloud docs warn that a configuration class picked up by component scanning applies to every client. I followed that advice but did not test the leak itself here.
Why a 503 can arrive as a RetryableException
If a response carries a Retry-After header, Feign’s default decoder throws RetryableException instead of the status-specific subclass. The retry section below shows that happening; it is the reason a plain 503 and a 503 with Retry-After look different in your logs.
Going deeper
- ErrorHandlingTest.java — the assertions behind the transcript
- Spring Boot 4 HTTP Service Clients — the
defaultStatusHandlerequivalent for@HttpExchange
Retries: one bean decides whether a call is sent once or three times
Spring Cloud OpenFeign does not retry by default. To turn retries on you declare aRetryer bean. RetryConfig.java allows three attempts, and RetryingStudentClient.java uses it; NoRetryStudentClient.java is the same call without it.
package com.ankurm.feign.client;
import feign.Retryer;
import org.springframework.context.annotation.Bean;
public class RetryConfig {
@Bean
Retryer retryer() {
return new Retryer.Default(50, 200, 3); // period 50 ms, max period 200 ms, at most 3 attempts
}
}
The fake server answers 503 with Retry-After: 0 for the first two calls to a key and 200 after that, and counts the calls it receives. Transcript: 05-retries.txt.
Server answers 503 + 'Retry-After: 0' for the first 2 calls, then 200.
no Retryer bean (the default) : RetryableException, server saw 1 call(s)
Retryer.Default(50,200,3) GET : success Student[id=3, name=flaky-b, branch=CS], server saw 3 call(s)
same Retryer, server keeps 503 : RetryableException, server saw 3 call(s)
same Retryer on a POST : success Student[id=3, name=flaky-d, branch=CS], server saw 3 call(s) for ONE client call
Retryer the first 503 is thrown to the caller and the server saw one call; with a three-attempt Retryer the same client succeeds on the third attempt. When the server never recovers, the client gives up after exactly three attempts.
The last line is the trap. The same Retryer also resent a POST: the server saw three calls for one client call. A retried write can create three records or charge a card three times. Either keep retries off clients that write, or make the endpoint idempotent before turning them on.
Going deeper
- RetryTest.java — asserts 1, 3, 3 and 3 server calls
- Resilience4j Circuit Breaker in Spring Boot — retries and circuit breakers together
Resilience: fallbacks, and a one-second limit you did not ask for
Hystrix-era Feign had fallback support built around Hystrix. The modern wiring goes through Spring Cloud CircuitBreaker, backed here by Resilience4j. Switching it on is one property, in application-fallback.yml:spring:
cloud:
openfeign:
circuitbreaker:
enabled: true
Then name a fallback class on the client. ResilientStudentClient.java declares the contract and StudentClientFallback.java implements it:
package com.ankurm.feign.client;
import com.ankurm.feign.Student;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "resilient", url = "${demo.remote-url}", fallback = StudentClientFallback.class)
public interface ResilientStudentClient {
@GetMapping("/api/students/{id}")
Student findById(@PathVariable("id") int id);
@PostMapping("/api/students/orders/{key}")
Student placeOrder(@PathVariable("key") String key, @RequestParam("failures") int failures);
}
package com.ankurm.feign.client;
import com.ankurm.feign.Student;
import org.springframework.stereotype.Component;
/** Reads degrade to a placeholder. Writes must NOT pretend to succeed. */
@Component
class StudentClientFallback implements ResilientStudentClient {
@Override
public Student findById(int id) {
return new Student(id, "unknown", "unknown");
}
@Override
public Student placeOrder(String key, int failures) {
throw new IllegalStateException("student-service down; order " + key + " not placed");
}
}
With the server answering 503, the read fell back to a placeholder and the write threw. The last block is a surprise I hit while testing: with circuitbreaker.enabled=true, every Feign client is wrapped, including ones with no fallback. Transcript: 06-fallback.txt.
findById(503), server answers 503 -> Student[id=503, name=unknown, branch=unknown]
placeOrder(w), server answers 503 -> IllegalStateException: student-service down; order w not placed
StudentClient.slow(3000) with circuitbreaker.enabled=true and NO read-timeout configured:
threw org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException after about 1000 ms
message: No fallback available.
cause : java.util.concurrent.TimeoutException
The unconfigured StudentClient, which had waited 3 seconds happily before, now failed after about one second with a TimeoutException behind NoFallbackAvailableException. I did not set that limit; it comes from the circuit-breaker wrapper’s time limiter, and I did not look up its exact configuration key, so I show the effect and not a fix.
A fallback that pretends a write succeeded is a data-loss bug. Returning an empty list or a placeholder is a fine fallback for reads. For writes, fail loudly (as placeOrder does above) or queue the request; a fallback that fakes a successful POST is a data-loss bug wearing a resilience costume.
If you turn the circuit breaker on, also set explicit timeouts
Because the wrapper applies to all clients, the one-second behaviour in the transcript affects a slow endpoint you had never touched. Test every slow call after enabling it, and set per-client read timeouts as in the timeout section so the failure you get is the one you chose. The wrapper also decorates @HttpExchange clients by default when the circuit-breaker starter is on the classpath; the last section shows what that does to an error.
Going deeper
- FallbackTest.java — the test that produced the transcript
- Resilience4j Circuit Breaker in Spring Boot
Pitfalls
1. Unnamed @PathVariable. Feign proxies cannot always infer parameter names; it depends on the-parameters compiler flag. UnnamedPathVariableClient.java omits the name on purpose. It works in a normal Boot build, because the Boot parent compiles with -parameters. no-parameters.sh compiles without the flag and captures what happens, in 09-no-parameters.txt:
package com.ankurm.feign.client;
import com.ankurm.feign.Student;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/** Deliberately breaks the rule above: no name in @PathVariable. Works only if compiled with -parameters. */
@FeignClient(name = "unnamed", url = "${demo.remote-url}")
public interface UnnamedPathVariableClient {
@GetMapping("/api/students/{id}")
Student byId(@PathVariable int id);
}
mvn -Pnoparams -Dtest=UnnamedPathVariableTest test (maven-compiler-plugin <parameters>false</parameters>)
Caused by: java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.ankurm.feign.client.UnnamedPathVariableClient': FactoryBean threw exception on object creation
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 7.498 s <<< FAILURE! -- in com.ankurm.feign.UnnamedPathVariableTest
The error reads like a framework bug but is fixed by writing @PathVariable("id") explicitly. The same applies to @RequestParam. Note that here it fails at startup, while the proxy is built, not on the first call.
2. FeignException on every non-2xx. Covered above: catch and translate per call, or register an ErrorDecoder once.
3. Inheriting server contracts. It is tempting to share one interface between the @RestController and the @FeignClient. Resist it: the official docs warn against contract inheritance, and in practice it couples deployables so a server-side refactor breaks every consumer’s build. I did not exercise this one in the module; it is the documented advice.
4. The old property prefix. Covered in the timeout section: feign.client.* silently does not bind, which is the first thing to check when timeouts “don’t work”.
Going deeper
- no-parameters.sh — how the failure is reproduced
- run-all.sh — regenerates every output file in one command
When to use @HttpExchange instead
Spring’s HTTP interface clients give you the same declarative style with no Feign dependency,RestClient underneath, and registration through Boot. HttpStudentClient.java is the same contract as StudentClient:
package com.ankurm.feign.client;
import com.ankurm.feign.Student;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.service.annotation.GetExchange;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;
/** The same contract as StudentClient, as a Spring HTTP interface: no extra starter, RestClient underneath. */
@HttpExchange("/api/students")
public interface HttpStudentClient {
@GetExchange
List<Student> findAll();
@GetExchange("/{id}")
Student findById(@PathVariable("id") int id);
@PostExchange
Student create(@RequestBody Student student);
}
It is registered by the @ImportHttpServices line in the application class and pointed at the server by spring.http.serviceclient.students.base-url (both are in the files shown earlier). The calls return the same data: 07-http-interface.txt.
findAll() -> [Student[id=1, name=Asha, branch=CS], Student[id=2, name=Ravi, branch=IT], Student[id=3, name=Meera, branch=EXTC]]
findById(2) -> Student[id=2, name=Student-2, branch=CS]
create(Kiran, ME) -> Student[id=100, name=Kiran, branch=ME]
findById(99), circuit breaker starter on the classpath (default):
exception : org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException
message : No fallback available.
cause : org.springframework.web.client.HttpClientErrorException$NotFound
Notice the error. The 404 did not come back as HttpClientErrorException$NotFound; it came back as NoFallbackAvailableException with the 404 as its cause. That is Spring Cloud’s circuit-breaker wrapper again, active because the Resilience4j starter is on the classpath. Setting spring.cloud.circuitbreaker.http-services.enabled=false restores the plain exception, in 08-http-interface-plain-errors.txt:
findById(99) with spring.cloud.circuitbreaker.http-services.enabled=false:
exception : org.springframework.web.client.HttpClientErrorException$NotFound
message : 404 Not Found: "{"detail":"No student with id 99","status":404,"title":"Not Found"}"
If you migrate Feign clients that relied on a fallback class, the equivalent for HTTP interfaces ships in Spring Cloud as HttpServiceFallback; I found the class in the spring-cloud-commons jar but did not exercise it here.
My decision rule: an existing Feign estate, or a need for Feign-specific features (ErrorDecoder, the per-client config tree, contract customization), means stay on OpenFeign. A new Boot 4 service should start with @HttpExchange. The interface shape is so similar that a later conversion is mostly annotation renames: @GetMapping becomes @GetExchange, @FeignClient becomes a group or a base URL, ErrorDecoder becomes a status handler, Retryer becomes Framework’s retry support.
Should you convert a working Feign client at all? Only if something forces you to. OpenFeign still works on Boot 4.2.0 as the runs above show, and a conversion changes your error types and your retry and fallback wiring, which is where the bugs hide. Convert when you are already touching the client, or when you want to drop the extra dependency, and do it one client at a time.
Going deeper
- Spring Boot 4 HTTP Service Clients: @HttpExchange Interfaces with RestClient
- RestTemplate to RestClient Migration Guide
- Spring HTTP interface clients reference
- HttpInterfaceTest.java and HttpInterfacePlainTest.java
AI Prompts for Feign Work
Prompts that save time on Feign work. Each one is a template; replace the bracketed parts. They are prompts, not tested code.
Migrate Netflix-Era Clients
Upgrade this Netflix Feign / Spring Boot 2.x client to Spring Cloud OpenFeign on Boot 4.x: [paste interface and config here]. Fix package imports, convert feign.client.* properties to spring.cloud.openfeign.*, replace Hystrix fallback wiring with the CircuitBreaker integration, and name every @PathVariable explicitly.
What it does: The full legacy-to-modern conversion including both silent breakages (property prefix, parameter names).
When to use it: Per client interface during a Boot 2 → Boot 4 migration.
Generate a Client from an API
From this OpenAPI spec or controller: [paste here], generate a @FeignClient interface with DTO records, explicit parameter names, and per-client timeout configuration appropriate for a [latency profile] dependency.
What it does: Produces the boilerplate — interface, records, config block — in one consistent pass.
When to use it: When wiring a new downstream dependency.
Design an ErrorDecoder
My Feign clients call these services with these error contracts: [paste status-code/error-body conventions here]. Write an ErrorDecoder that maps them to domain exceptions, preserving retryable vs non-retryable classification for Resilience4j.
What it does: Centralizes error translation instead of FeignException catches scattered across services.
When to use it: Once you have more than two or three Feign clients.
Audit Fallback Safety
Review these Feign fallback classes: [paste here]. Flag any fallback on a write operation that returns a fabricated success, and propose safe alternatives (queueing, explicit ServiceUnavailable, compensation) for each.
What it does: Catches the data-loss-disguised-as-resilience pattern before production does.
When to use it: Code review for any client with a fallback class.
Decide Feign vs HTTP Interfaces
My project: [describe Boot version, number of clients, Feign features used]. Recommend OpenFeign vs @HttpExchange for new clients and whether converting existing ones is worth it, with a conversion-effort estimate per feature in use.
What it does: Turns the strategic question into a concrete, feature-by-feature recommendation.
When to use it: At architecture-decision time on any Boot 3.2+ codebase.
Conclusion
OpenFeign on Spring Boot 4.2 is a solid, supported home for declarative clients: service-ID resolution through the load balancer, retries through aRetryer, fallbacks through Spring Cloud CircuitBreaker, configuration under spring.cloud.openfeign. Name your path variables, decode errors centrally, never fake success in a write fallback, and be careful what you turn on globally: a Retryer resends your POSTs, and the circuit-breaker switch wraps every client. For greenfield Boot 4 services, give @HttpExchange the first look.
See Also
- Spring Cloud Netflix to Modern Alternatives: Complete Migration Guide
- Spring Boot 4 HTTP Service Clients (@HttpExchange)
- Service Discovery with Eureka in Spring Boot 3.x
- Resilience4j Circuit Breaker in Spring Boot
- RestTemplate to RestClient Migration Guide
No Comments yet!