@EnableFeignClients is a Spring Cloud OpenFeign annotation that tells Spring to scan for interfaces annotated with @FeignClient and create a REST client bean for each one. You declare an interface with Spring MVC style annotations, and Spring generates the HTTP-calling implementation at startup. You add it once, on a configuration or application class.
@EnableFeignClients does@EnableFeignClients doesFeign is a declarative HTTP client. Instead of building requests with a template, you describe the remote API as a Java interface. @EnableFeignClients (package org.springframework.cloud.openfeign) registers a scanner that finds every @FeignClient interface in the chosen packages and registers a proxy bean for it, which you then inject like any other bean.
Its main attributes:
| Attribute | Purpose |
|---|---|
basePackages / basePackageClasses | Where to scan for @FeignClient interfaces (default is the package of the annotated class) |
clients | Register specific client interfaces instead of scanning |
defaultConfiguration | Configuration class applied to all clients (encoder, decoder, logger, interceptors) |
Add the starter spring-cloud-starter-openfeign, then enable the scan and declare an interface.
The name is the logical service name. With a discovery client on the classpath, Spring Cloud LoadBalancer resolves it to a running instance. Without discovery, set a fixed url instead, for example url = "http://localhost:9000".
Per-client settings live in properties, which avoids extra configuration classes.
Use default for all clients and the client name for a single one. For deeper changes, such as a custom ErrorDecoder or a RequestInterceptor that adds an authorization header, declare beans in a configuration class and reference it through @FeignClient(configuration = ...) or defaultConfiguration. Do not annotate that class with @Configuration if it should apply to one client only, otherwise it leaks to every client.
Netflix Hystrix is gone from current Spring Cloud releases. Resilience is now handled through Spring Cloud CircuitBreaker, usually backed by Resilience4j.
A FallbackFactory is preferred over a plain fallback class because it receives the cause of the failure, which you can log or use to decide the response.
Feign is a long-standing and well-known choice, but it is not the only declarative client. Spring Framework 6 introduced HTTP interface clients, where you annotate an interface with @HttpExchange and build it from RestClient or WebClient through HttpServiceProxyFactory. They need no extra Spring Cloud dependency. Choose Feign when you already rely on its integrations (load balancing, circuit breaker properties, many existing clients), and consider HTTP interfaces for new code that does not need them.
NoSuchBeanDefinitionException for a client: the interface is outside the scanned packages. Set basePackages or clients.No Feign Client for loadBalancing defined: add spring-cloud-starter-loadbalancer, or specify a url.@EnableFeignClients mandatory?Yes, for interfaces to be discovered. Without it @FeignClient interfaces are never turned into beans.
Yes. Set the url attribute on @FeignClient, or use any other discovery client or Kubernetes service names.
Spring Cloud OpenFeign is blocking. For reactive code use WebClient, optionally with an HTTP interface client.
Declare a RequestInterceptor bean and add the header inside it, then apply it through client configuration.
@EnableFeignClients enables scanning for @FeignClient interfaces and wires generated proxies into your Spring context. Combine it with a discovery client and Spring Cloud LoadBalancer, tune timeouts through properties, handle failures with the CircuitBreaker integration, and weigh it against Spring's HTTP interface clients for new projects.