### Enable Feign Clients Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Example of how to enable Feign clients in a Spring Boot application by adding the `@EnableFeignClients` annotation. ```APIDOC ## Enable Feign Clients To enable Feign clients in your Spring Boot application, annotate your main application class with `@EnableFeignClients`. ### Example ```java @SpringBootApplication @EnableFeignClients public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` ``` -------------------------------- ### StoreClient Interface Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Example of a Feign client interface using Spring MVC annotations to define REST endpoints for interacting with a 'stores' service. ```APIDOC ## StoreClient Interface This interface demonstrates how to define a Feign client for a 'stores' service using Spring MVC annotations. ### Interface Definition ```java @FeignClient("stores") public interface StoreClient { @RequestMapping(method = RequestMethod.GET, value = "/stores") List getStores(); @RequestMapping(method = RequestMethod.GET, value = "/stores") Page getStores(Pageable pageable); @RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json") Store update(@PathVariable("storeId") Long storeId, Store store); @RequestMapping(method = RequestMethod.DELETE, value = "/stores/{storeId:\d+}") void delete(@PathVariable Long storeId); } ``` ### Notes - The `@FeignClient` annotation specifies the logical name of the client ("stores"). - The `url` attribute can be used to specify an absolute URL or a hostname. - The bean name in the application context is the fully qualified name of the interface. - You can use the `qualifiers` attribute of `@FeignClient` to specify a custom alias value. ``` -------------------------------- ### Configure Circuit Breakers with Properties Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Configure circuit breaker instances for Feign clients using application properties. This example shows how to enable circuit breakers, alphanumeric IDs, and set minimum calls and timeout durations for a specific client method. ```java @FeignClient(url = "http://localhost:8080") public interface DemoClient { @GetMapping("demo") String getDemo(); } ``` ```yaml spring: cloud: openfeign: circuitbreaker: enabled: true alphanumeric-ids: enabled: true resilience4j: circuitbreaker: instances: DemoClientgetDemo: minimumNumberOfCalls: 69 timelimiter: instances: DemoClientgetDemo: timeoutDuration: 10s ``` -------------------------------- ### Create Custom Feign Clients with Interceptors Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Use the Feign Builder API to create custom Feign clients. This example demonstrates creating two clients with the same interface but different basic authentication interceptors. ```java @Import(FeignClientsConfiguration.class) class FooController { private FooClient fooClient; private FooClient adminClient; @Autowired public FooController(Client client, Encoder encoder, Decoder decoder, Contract contract, MicrometerObservationCapability micrometerObservationCapability) { this.fooClient = Feign.builder().client(client) .encoder(encoder) .decoder(decoder) .contract(contract) .addCapability(micrometerObservationCapability) .requestInterceptor(new BasicAuthRequestInterceptor("user", "user")) .target(FooClient.class, "https://PROD-SVC"); this.adminClient = Feign.builder().client(client) .encoder(encoder) .decoder(decoder) .contract(contract) .addCapability(micrometerObservationCapability) .requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin")) .target(FooClient.class, "https://PROD-SVC"); } } ``` -------------------------------- ### Define a Feign Client Interface Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Create an interface annotated with @FeignClient to define a declarative REST client. Use Spring MVC annotations like @RequestMapping for HTTP method and path mapping. This example shows how to fetch lists, paginated data, update, and delete stores. ```java @FeignClient("stores") public interface StoreClient { @RequestMapping(method = RequestMethod.GET, value = "/stores") List getStores(); @RequestMapping(method = RequestMethod.GET, value = "/stores") Page getStores(Pageable pageable); @RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json") Store update(@PathVariable("storeId") Long storeId, Store store); @RequestMapping(method = RequestMethod.DELETE, value = "/stores/{storeId:\d+}") void delete(@PathVariable Long storeId); } ``` -------------------------------- ### Customize Circuit Breaker Naming Pattern Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Provide a bean of CircuitBreakerNameResolver to change the circuit breaker name pattern. This example sets the pattern to `feignClientName_methodName`. ```java @Configuration public class FooConfiguration { @Bean public CircuitBreakerNameResolver circuitBreakerNameResolver() { return (String feignClientName, Target target, Method method) -> feignClientName + "_" + method.getName(); } } ``` -------------------------------- ### Enable X-Forwarded Headers Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Enable support for X-Forwarded-Host and X-Forwarded-Proto headers in load balancing by setting this flag to true. ```properties spring.cloud.loadbalancer.x-forwarded.enabled=true ``` -------------------------------- ### Handling Feign Clients in Early Initialization Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Provides a workaround for potential initialization errors when using Feign clients early in the application lifecycle. ```APIDOC ## Autowiring Feign Client with ObjectProvider ### Description This snippet shows how to safely inject a Feign client using `ObjectProvider` to avoid potential initialization errors during early application startup. ### Method N/A (Dependency Injection pattern) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ### Notes Using `ObjectProvider` defers the instantiation and dependency resolution of the Feign client until it's actually needed, mitigating issues that can arise during the bean initialization phase. ``` -------------------------------- ### Use ObjectProvider for Feign Client Autowiring Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html To avoid early initialization errors when using Feign clients during bean initialization, autowire the client using `ObjectProvider`. ```java @Autowired ObjectProvider testFeignClient; ``` -------------------------------- ### Implement Feign Client Using Inheritance Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Create a Feign client interface that extends a base interface to inherit its methods. This allows for modular API definitions. ```java @RestController public class UserResource implements UserService { } ``` ```java package project.user; @FeignClient("users") public interface UserClient extends UserService { } ``` -------------------------------- ### Enable Feign Request and Response Compression Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Enable GZIP compression for Feign requests or responses by setting the respective properties. This can help reduce network bandwidth usage. ```properties spring.cloud.openfeign.compression.request.enabled=true spring.cloud.openfeign.compression.response.enabled=true ``` -------------------------------- ### Configure Feign Request Compression Settings Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Customize Feign request compression by specifying allowed MIME types and a minimum request size threshold. Compression is only applied to requests exceeding this size. ```properties spring.cloud.openfeign.compression.request.enabled=true spring.cloud.openfeign.compression.request.mime-types=text/xml,application/xml,application/json spring.cloud.openfeign.compression.request.min-request-size=2048 ``` -------------------------------- ### Configure Default Feign Client Properties Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Set default configuration properties for all Feign clients by using the 'default' feign name in application.yml. This allows for global settings like connect and read timeouts, and logger level. ```yaml spring: cloud: openfeign: client: config: default: connectTimeout: 5000 readTimeout: 5000 loggerLevel: basic ``` -------------------------------- ### Use MicrometerCapability for Metrics-Only Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Enable metrics-only support for Feign clients using MicrometerCapability by disabling Micrometer support and creating a MicrometerCapability bean with a MeterRegistry. ```java @Configuration public class FooConfiguration { @Bean public MicrometerCapability micrometerCapability(MeterRegistry meterRegistry) { return new MicrometerCapability(meterRegistry); } } ``` -------------------------------- ### Configure Feign Client with application.yml Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Configure Feign client properties such as timeouts, logger level, error decoder, retryer, and more via application.yml. These properties are applied to a specific Feign client identified by its name (e.g., 'feignName'). ```yaml spring: cloud: openfeign: client: config: feignName: url: http://remote-service.com connectTimeout: 5000 readTimeout: 5000 loggerLevel: full errorDecoder: com.example.SimpleErrorDecoder retryer: com.example.SimpleRetryer defaultQueryParameters: query: queryValue defaultRequestHeaders: header: headerValue requestInterceptors: - com.example.FooRequestInterceptor - com.example.BarRequestInterceptor responseInterceptor: com.example.BazResponseInterceptor dismiss404: false encoder: com.example.SimpleEncoder decoder: com.example.SimpleDecoder contract: com.example.SimpleContract capabilities: - com.example.FooCapability - com.example.BarCapability queryMapEncoder: com.example.SimpleQueryMapEncoder micrometer.enabled: false ``` -------------------------------- ### Configure Feign Client with Java Configuration Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Use a @Configuration class to define beans that override default Feign client settings like Contract and RequestInterceptor. This configuration can be applied to a specific @FeignClient. ```java @Configuration public class FooConfiguration { @Bean public Contract feignContract() { return new feign.Contract.Default(); } @Bean public BasicAuthRequestInterceptor basicAuthRequestInterceptor() { return new BasicAuthRequestInterceptor("user", "password"); } } ``` -------------------------------- ### Implement Feign Fallback with Factory Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Implement a fallback for a Feign client using a fallback factory to gain access to the cause of the fallback. The factory creates an instance of the fallback implementation. ```java @FeignClient(name = "testClientWithFactory", url = "http://localhost:${server.port}/", fallbackFactory = TestFallbackFactory.class) protected interface TestClientWithFactory { @RequestMapping(method = RequestMethod.GET, value = "/hello") Hello getHello(); @RequestMapping(method = RequestMethod.GET, value = "/hellonotfound") String getException(); } @Component static class TestFallbackFactory implements FallbackFactory { @Override public FallbackWithFactory create(Throwable cause) { return new FallbackWithFactory(); } } static class FallbackWithFactory implements TestClientWithFactory { @Override public Hello getHello() { throw new NoFallbackAvailableException("Boom!", new RuntimeException()); } @Override public String getException() { return "Fixed response"; } } ``` -------------------------------- ### Feign Caching with @Cacheable Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Demonstrates how to enable caching for Feign client methods using Spring's @Cacheable annotation when @EnableCaching is configured. ```APIDOC ## GET /demo/{filterParam} ### Description This endpoint retrieves data and caches the response using the @Cacheable annotation. The cache name is 'demo-cache' and the key is derived from the 'keyParam' method argument. ### Method GET ### Endpoint /demo/{filterParam} ### Parameters #### Path Parameters - **filterParam** (String) - Required - The parameter used in the path. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **String** - The response from the demo endpoint. #### Response Example "response string" ### Notes Caching is enabled by default if `@EnableCaching` is used. It can be disabled via the `spring.cloud.openfeign.cache.enabled=false` property. ``` -------------------------------- ### Feign HATEOAS Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Shows how Feign clients can serialize and deserialize HATEOAS representation models when HATEOAS support is enabled. ```APIDOC ## GET /stores ### Description This endpoint retrieves a collection of stores, supporting HATEOAS representations like CollectionModel. ### Method GET ### Endpoint /stores ### Parameters None ### Request Example None ### Response #### Success Response (200) - **CollectionModel** - A HATEOAS CollectionModel containing Store resources. #### Response Example ```json { "_embedded": { "stores": [ { ... store object ... }, { ... store object ... } ] }, "_links": { ... links ... } } ``` ### Notes HATEOAS support is enabled by default if `spring-boot-starter-hateoas` or `spring-boot-starter-data-rest` is included in the project. ``` -------------------------------- ### Enable Feign Clients in Spring Boot Application Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Annotate your main Spring Boot application class with @EnableFeignClients to activate Feign client auto-configuration. This enables the discovery and registration of Feign client interfaces. ```java @SpringBootApplication @EnableFeignClients public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` -------------------------------- ### Define Query Map Parameters with POJO Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Define a POJO class to hold query parameters. Getters and setters are required for the parameters to be correctly mapped. ```java // Params.java public class Params { private String param1; private String param2; // [Getters and setters omitted for brevity] } ``` -------------------------------- ### Provide URL in @FeignClient and application.yml Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html When both the `@FeignClient` annotation and `application.yml` specify a URL, the annotation's `url` attribute takes precedence. The property in `application.yml` is unused in this configuration. ```java @FeignClient(name="testClient", url="http://localhost:8081") ``` ```yaml spring.cloud.openfeign.client.config.testClient.url=http://localhost:8081 ``` -------------------------------- ### Implement Feign Fallback with Class Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Implement a fallback for a Feign client by providing a class that implements the client interface. This fallback is invoked when the circuit is open or an error occurs. Ensure the fallback class is a Spring bean. ```java @FeignClient(name = "test", url = "http://localhost:${server.port}/", fallback = Fallback.class) protected interface TestClient { @RequestMapping(method = RequestMethod.GET, value = "/hello") Hello getHello(); @RequestMapping(method = RequestMethod.GET, value = "/hellonotfound") String getException(); } @Component static class Fallback implements TestClient { @Override public Hello getHello() { throw new NoFallbackAvailableException("Boom!", new RuntimeException()); } @Override public String getException() { return "Fixed response"; } } ``` -------------------------------- ### Customize MicrometerObservationCapability Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Register a custom MicrometerObservationCapability bean to customize how Feign clients are observed by Micrometer. This requires an ObservationRegistry bean to be available. ```java @Configuration public class FooConfiguration { @Bean public MicrometerObservationCapability micrometerObservationCapability(ObservationRegistry registry) { return new MicrometerObservationCapability(registry); } } ``` -------------------------------- ### Feign CollectionFormat Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Demonstrates how to specify the collection format for query parameters using the @CollectionFormat annotation. ```APIDOC ## GET /test ### Description This endpoint performs a request where the string parameter is formatted as a CSV collection. ### Method GET ### Endpoint /test ### Parameters #### Path Parameters None #### Query Parameters - **test** (String) - Required - The string to be sent, formatted as CSV. #### Request Body None ### Request Example None ### Response #### Success Response (200) - **ResponseEntity** - The response entity from the request. #### Response Example ``` HTTP/1.1 200 OK Content-Type: application/json { ... response body ... } ``` ### Notes The `@CollectionFormat(feign.CollectionFormat.CSV)` annotation is used to specify the CSV format instead of the default EXPLODED format. ``` -------------------------------- ### Provide URL in @FeignClient Annotation Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Use the `url` attribute in the `@FeignClient` annotation to directly specify the URL. This method bypasses load balancing. ```java @FeignClient(name="testClient", url="http://localhost:8081") ``` -------------------------------- ### Define Base Interface for Feign Client Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Define a base interface with common API methods that can be extended by multiple Feign clients. This promotes code reuse and organization. ```java public interface UserService { @RequestMapping(method = RequestMethod.GET, value = "/users/{id}") User getUser(@PathVariable("id") long id); } ``` -------------------------------- ### Implement LoadBalancerFeignRequestTransformer Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Implement this interface to transform load-balanced HTTP requests. You can add custom headers like X-ServiceId and X-InstanceId based on the ServiceInstance. ```java @Bean public LoadBalancerFeignRequestTransformer transformer() { return new LoadBalancerFeignRequestTransformer() { @Override public Request transformRequest(Request request, ServiceInstance instance) { Map> headers = new HashMap<>(request.headers()); headers.put("X-ServiceId", Collections.singletonList(instance.getServiceId())); headers.put("X-InstanceId", Collections.singletonList(instance.getInstanceId())); return Request.create(request.httpMethod(), request.url(), headers, request.body(), request.charset(), request.requestTemplate()); } }; } ``` -------------------------------- ### AOT/Native Image: Override URL with System Property Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html If the `url` is set via properties during build time, it can be overridden at runtime for AOT/native images using a system property. This requires the `url` to be set via properties initially. ```bash -Dspring.cloud.openfeign.client.config.[clientId].url=[url] ``` -------------------------------- ### Specify Custom Feign Configuration Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Use the `configuration` attribute in `@FeignClient` to specify a custom configuration class. This class will override or supplement the default Feign beans. ```java @FeignClient(name = "stores", configuration = FooConfiguration.class) public interface StoreClient { //.. } ``` -------------------------------- ### Enable Feign Client Refresh Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Enable dynamic refresh behavior for Feign clients. This allows properties like connectTimeout, readTimeout, and URLs to be refreshed at runtime. ```properties spring.cloud.openfeign.client.refresh-enabled=true ``` -------------------------------- ### Use Placeholders in FeignClient Attributes Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Placeholders are supported in the `name` and `url` attributes of the `@FeignClient` annotation, allowing for dynamic configuration. ```java @FeignClient(name = "${feign.name}", url = "${feign.url}") public interface StoreClient { //.. } ``` -------------------------------- ### Feign @QueryMap Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Illustrates how to use the @SpringQueryMap annotation to map a POJO or Map to query parameters for a Feign client request. ```APIDOC ## GET /demo ### Description This endpoint accepts query parameters mapped from a POJO using the @SpringQueryMap annotation. ### Method GET ### Endpoint /demo ### Parameters #### Path Parameters None #### Query Parameters - **param1** (String) - Optional - Parameter from the Params class. - **param2** (String) - Optional - Parameter from the Params class. #### Request Body None ### Request Example ```json { "param1": "value1", "param2": "value2" } ``` ### Response #### Success Response (200) - **String** - The response from the demo endpoint. #### Response Example "response string" ### Notes Custom query map encoding can be achieved by implementing a `QueryMapEncoder` bean. ``` -------------------------------- ### Configure Feign Logger Level to FULL Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Set the Feign logger level to FULL for detailed logging of requests and responses, including headers and body. This is done by defining a Logger.Level bean in your configuration. ```java @Configuration public class FooConfiguration { @Bean Logger.Level feignLoggerLevel() { return Logger.Level.FULL; } } ``` -------------------------------- ### Configure Feign Builder with Prototype Scope Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html To disable Spring Cloud CircuitBreaker support on a per-client basis, create a Feign.Builder with the "prototype" scope. ```java @Configuration public class FooConfiguration { @Bean @Scope("prototype") public Feign.Builder feignBuilder() { return Feign.builder(); } } ``` -------------------------------- ### Provide URL in application.yml Only Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html If the URL is not in the `@FeignClient` annotation but is defined in `application.yml`, it will be used without load balancing. If `spring.cloud.openfeign.client.refresh-enabled` is true, this URL can be refreshed. ```java @FeignClient(name="testClient") ``` ```yaml spring.cloud.openfeign.client.config.testClient.url=http://localhost:8081 ``` -------------------------------- ### Feign @MatrixVariable Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Explains how to use the @MatrixVariable annotation in Feign clients, including requirements for path segment placeholders. ```APIDOC ## GET /objects/links/{matrixVars} ### Description This endpoint retrieves objects using matrix variables defined in the path. The matrix variables are passed as a Map. ### Method GET ### Endpoint /objects/links/{matrixVars} ### Parameters #### Path Parameters - **matrixVars** (Map>) - Required - A map containing matrix variables. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Map>** - A map where keys are variable names and values are lists of strings. #### Response Example { "var1": ["val1", "val2"], "var2": ["val3"] } ### Notes Spring Cloud OpenFeign requires the path segment placeholder name to match the `@MatrixVariable` name or the annotated variable name. ``` -------------------------------- ### Enable Caching for Feign Client Interface Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Use the `@EnableCaching` annotation to enable caching for Feign clients. The `@Cacheable` annotation can then be applied to client methods to specify cache names and keys. ```java public interface DemoClient { @GetMapping("/demo/{filterParam}") @Cacheable(cacheNames = "demo-cache", key = "#keyParam") String demoEndpoint(String keyParam, @PathVariable String filterParam); } ``` -------------------------------- ### Feign Client for HATEOAS Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html When HATEOAS support is enabled, Feign clients can serialize and deserialize HATEOAS representation models like EntityModel, CollectionModel, and PagedModel. ```java @FeignClient("demo") public interface DemoTemplate { @GetMapping(path = "/stores") CollectionModel getStores(); } ``` -------------------------------- ### AOT/Native Image: Disable Client Refresh Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html For AOT or native image compatibility, ensure `spring.cloud.openfeign.client.refresh-enabled` is not set to `true`. The default setting is disabled. ```properties spring.cloud.openfeign.client.refresh-enabled=false ``` -------------------------------- ### Resolve URL from @FeignClient Name Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html When the URL is neither in the annotation nor in configuration properties, Feign resolves the URL using the `name` attribute of the `@FeignClient` annotation, enabling load balancing. ```java @FeignClient(name="testClient") ``` -------------------------------- ### Configure CollectionFormat for Feign Client Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Use the `@CollectionFormat` annotation to specify the collection format for method parameters. The `CSV` format can be used instead of the default `EXPLODED`. ```java @FeignClient(name = "demo") protected interface DemoFeignClient { @CollectionFormat(feign.CollectionFormat.CSV) @GetMapping(path = "/test") ResponseEntity performRequest(String test); } ``` -------------------------------- ### Handle Matrix Variables with Map Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html When a map is passed as a method argument for `@MatrixVariable`, the path segment is created by joining key-value pairs from the map with '='. Ensure the path segment placeholder name matches the variable name. ```java @GetMapping("/objects/links/{matrixVars}") Map> getObjects(@MatrixVariable Map> matrixVars); ``` -------------------------------- ### Register a Custom Feign Capability Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Add a custom capability to a Feign client by defining a bean of type Capability. This allows modification of the client's behavior, such as decorating the Client instance. ```java @Configuration public class FooConfiguration { @Bean Capability customCapability() { return new CustomCapability(); } } ``` -------------------------------- ### Specify Feign Client with Context ID Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Use the 'contextId' attribute in @FeignClient to provide unique names for configurations when multiple clients share the same name or URL, preventing bean definition collisions. ```java @FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class) public interface FooClient { //.. } ``` ```java @FeignClient(contextId = "barClient", name = "stores", configuration = BarConfiguration.class) public interface BarClient { //.. } ``` -------------------------------- ### Set Feign Client Logging Level Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Configure the logging level for a specific Feign client to DEBUG in your application properties. Feign logging is only active at the DEBUG level. ```yaml logging.level.project.user.UserClient: DEBUG ``` -------------------------------- ### Enable OAuth2 Support Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Enable OAuth2 support in Feign clients by setting this flag to true. This automatically configures an interceptor to add OAuth2 access tokens to requests. ```properties spring.cloud.openfeign.oauth2.enabled=true ``` -------------------------------- ### Disable Parent Context Inheritance for FeignClient Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Configure FeignClient to not inherit beans from the parent context by overriding `inheritParentConfiguration()` to return `false` in a `FeignClientConfigurer` bean. ```java @Configuration public class CustomConfiguration { @Bean public FeignClientConfigurer feignClientConfigurer() { return new FeignClientConfigurer() { @Override public boolean inheritParentConfiguration() { return false; } }; } } ``` -------------------------------- ### AOT/Native Image: Disable Lazy Attributes Resolution Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html To ensure compatibility with AOT or native image modes, verify that `spring.cloud.openfeign.lazy-attributes-resolution` is not set to `true`. This is disabled by default. ```properties spring.cloud.openfeign.lazy-attributes-resolution=false ``` -------------------------------- ### Use @SpringQueryMap for Query Parameter Maps Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Annotate a POJO or Map parameter with `@SpringQueryMap` to use it as a query parameter map in a Feign client. ```java @FeignClient("demo") public interface DemoTemplate { @GetMapping(path = "/demo") String demoEndpoint(@SpringQueryMap Params params); } ``` -------------------------------- ### AOT/Native Image: Disable Refresh Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html To run Spring Cloud OpenFeign clients in AOT or native image modes, ensure that `spring.cloud.refresh.enabled` is set to `false`. ```properties spring.cloud.refresh.enabled=false ``` -------------------------------- ### Lazy Attributes Resolution Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Configuration property to enable lazy resolution of attributes for Feign client beans. ```APIDOC ## Lazy Attributes Resolution By default, attributes in the `@FeignClient` annotation are resolved eagerly. To enable lazy resolution, set the following property: ### Property `spring.cloud.openfeign.lazy-attributes-resolution=true` ### Use Case Lazy attribute resolution should be used for Spring Cloud Contract test integration. ``` -------------------------------- ### Disable Primary Bean for Feign Client Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Configure a Feign client to not be marked as `@Primary`. This is useful when managing multiple Feign client beans of the same type to avoid ambiguity in dependency injection. ```java @FeignClient(name = "hello", primary = false) public interface HelloClient { // methods here } ``` -------------------------------- ### Disable Spring Data Converters Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html Set this property to false to disable automatic converters for Spring Data Page and Sort types when Jackson Databind and Spring Data Commons are present. ```properties spring.cloud.openfeign.autoconfiguration.jackson.enabled=false ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.