Spring Cloud OpenFeign lets you declare a REST client as a plain Java interface annotated with @FeignClient and Spring MVC annotations such as @GetMapping. Spring generates the implementation at startup, registers it as a bean, and routes calls through Spring Cloud LoadBalancer when you use a service name instead of a URL. To use it, add spring-cloud-starter-openfeign, put @EnableFeignClients on a configuration class, declare the interface, and inject it where you need it.
The Netflix pieces older tutorials rely on are gone. Hystrix and Ribbon were removed from Spring Cloud, and @EnableEurekaClient is no longer needed. This article shows the current setup for Spring Boot 3 and later, which uses the jakarta.* namespace and a Spring Cloud release train that matches your Boot version.
Import the Spring Cloud BOM so every Spring Cloud module uses a compatible version, then add the starter. Pick the release train that matches your Spring Boot version from the official Spring Cloud compatibility table; do not mix trains.
In Gradle, use implementation platform("org.springframework.cloud:spring-cloud-dependencies:<version>") and then the two starters without versions. The load balancer starter is needed only when you call services by name.
Add @EnableFeignClients to your application class or any @Configuration class. It scans for interfaces annotated with @FeignClient.
Then declare the client. A record works well as the response DTO because Jackson can deserialize records.
Each method maps to one HTTP call. Always give @PathVariable and @RequestParam an explicit name, because Feign cannot rely on parameter names being compiled into the class file. Inject the interface like any bean:
When you omit url, the name is treated as a logical service id. Spring Cloud LoadBalancer resolves it to concrete instances through whichever DiscoveryClient is on the classpath (Eureka, Consul, Kubernetes) and spreads calls across them, round robin by default.
For Eureka, add spring-cloud-starter-netflix-eureka-client and set eureka.client.service-url.defaultZone. Registration happens automatically; the old @EnableEurekaClient annotation is not required. Ribbon, which older tutorials mention for load balancing, was removed from Spring Cloud in favour of Spring Cloud LoadBalancer.
Prefer properties for per-client settings. Use default to apply a value to every client, or the client name to target one.
Timeouts are in milliseconds. Feign logs only at DEBUG level, so the logger for the client interface must be set to DEBUG as well. The levels are none, basic, headers and full.
For behaviour that cannot be expressed in properties, such as adding an authentication header to every call, define a RequestInterceptor bean in a configuration class and reference it with @FeignClient(configuration = ...).
Do not annotate that configuration class with @Configuration if it is meant for a single client, or component scanning will apply it to all of them.
Hystrix is no longer supported. The current approach is Spring Cloud CircuitBreaker with Resilience4j. Add spring-cloud-starter-circuitbreaker-resilience4j and enable the integration:
Then give the client a fallback. Use fallbackFactory when you need access to the cause of the failure.
Return a safe default only when that is truly acceptable for the caller. For writes, failing loudly is usually correct. You can tune thresholds and time limits with the standard Resilience4j properties.
To translate HTTP errors into your own exceptions, register an ErrorDecoder bean in the client configuration. By default Feign throws a FeignException subclass such as FeignException.NotFound for 4xx and 5xx responses.
Spring Framework 6 introduced HTTP interface clients (@HttpExchange) built on RestClient or WebClient. They give a similar declarative style without Spring Cloud, which is a good fit when you only need typed HTTP calls and not discovery or Feign's extension points.
| Need | OpenFeign | HTTP interface client |
|---|---|---|
| Declarative interface | Yes | Yes |
| Spring Cloud discovery and load balancing | Built in | Configure through the client builder |
| Circuit breaker integration | Property switch | Wire it yourself |
| Extra dependency | Spring Cloud | Spring Framework only |
Yes. Without it, @FeignClient interfaces are not scanned and no beans are created. You can list packages or classes with basePackages or clients when the interfaces live outside the application package.
No. Hystrix has been removed from Spring Cloud. Use Spring Cloud CircuitBreaker with Resilience4j and the spring.cloud.openfeign.circuitbreaker.enabled property.
Feign reads annotation values, not compiled parameter names. Write @PathVariable("id") and @RequestParam("name") explicitly.
Declare a RequestInterceptor bean in the client configuration, or add @RequestHeader to a method parameter for a per-call value.
Spring Cloud OpenFeign turns an annotated interface into a working HTTP client. Add the starter and the Spring Cloud BOM, enable scanning with @EnableFeignClients, and call services by name so Spring Cloud LoadBalancer picks an instance. Configure timeouts and logging through spring.cloud.openfeign.client.config, and use Resilience4j through Spring Cloud CircuitBreaker instead of the removed Hystrix.