VOOZH about

URL: https://www.geeksforgeeks.org/advance-java/change-default-feign-client-implementation-in-spring-boot/

⇱ How to Change Default Feign Client Implementation in Spring Boot? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Change Default Feign Client Implementation in Spring Boot?

Last Updated : 23 Jul, 2025

Feign is the declarative HTTP client developed by Netflix. It can simplify the process of calling RESTful web services by defining the client interfaces and using annotations. By default, Feign can use the java HTTPURLConnection for making the HTTP requests. However, in some of the cases, we might want to change this default implementation to leverage a more feature-rich and performant HTTP client like Apache HttpClient.

In this article, we will guide how to change the default Feign client implementation in the Spring Boot application to use the Apache HttpClient.

Prerequisites

  • Basic knowledge of the Spring Boot and Feign.
  • Java Development Kit installed in your local system.
  • Maven dependency for building management.

Main Concept

The main concept can involves the configuration Feign to use the Apache HttpClient instead of the default HTTPURLConnection. It can requires adding the necessary dependencies for Apache HttpClient and Feign and then creating the configuration class to set up the Feign with Apache HttpClient.

Steps to Change the Default Feign Client Implementation

  1. Add dependencies: We can add the Spring Boot, Feign, and HttpClient dependencies to your pom.xml of the Spring application.
  2. Create the configuration class: We can configure Feign to use Apache HttpClient.
  3. Define the Feign Client Interface: Create the interface for the Feign client with the necessary annotations.
  4. Create the controller to test the Feign client: Create the REST controller to expose the endpoint that uses the service of the application.

Implementation of how to How to Change Default Feign Client implementation in Spring Boot

Create the External API

Step 1: Create the Spring project

We can create the spring project using spring Initializr on creating the project add the below dependencies into the project.

  • Spring Web
  • Lombok
  • Spring DevTools

Once create the project then the file structure then the file structure looks like the below image.

👁 externalfile

Step 2: Application Properties

spring.application.name=external-api
# application.properties
server.port=8081

Step 3: Create the ExternalApiController class

Go to src > main > java > org.example.externalapi > ExternalApiController and put the below code.

Step 4: Main class

No changes are required in the main class

pom.xml

Step 5: Run the application

Once complete the project then run the application, it will start at port 8081.

👁 externallog-compressed

Create the Feign-Client

Step 1: Create the Spring project

We can create the spring project using spring Initializr on creating the project add the below dependencies into the project.

  • Spring Web
  • Lombok
  • Spring DevTools
  • OpenFeign

External Dependencies:

 <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.github.openfeign/feign-httpclient -->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>13.2.1</version>
</dependency>

Once create the project then the file structure then the file structure looks like the below image.

👁 feignclientfile

Step 2: Configure the application properties

spring.application.name=feign-client
server.port=8080

Step 3: Create the FeignConfig class

Go to src > main > java > org.example.feigncleint > config > FeignConfig and put the below code.

Step 4: Create the ExampleClient class

Go to src > main > java > org.example.feigncleint > config > ExampleClient and put the below code.

@FeignClient: It can defines the Feign client with the specified name. URL and configuration class.

Step 5: Create the ExampleService class

Go to src > main > java > org.example.feigncleint > service > ExampleService and put the below code.

Step 6: Create the ExampleController class

Go to src > main > java > org.example.feigncleint > controller > ExampleController and put the below code.

Step 7: Main class

In main class, we can add the @EnableFeignClients to enable the feign clients functionalities of the application.

pom.xml

Step 8: Run the application

Once complete the project then run the application it will start at 8080.

👁 feignclientlog-compressed-(1)

Testing the Endpoint

GET http:localhost:8080/fetch?param= Hello Feign
👁 feignpost

By the following these steps, we can successfully change the default Feign client implementation in the Spring Boot application to use the Apache HttpClient. This setup can be allows you to leverage the advanced features and performance the optimizations of the Apache HttpClient.

Comment
Article Tags:

Explore