Please refer to the following link on how to customize it. https://codingnconcepts.com/spring-boot/change-default-feign-client-implementation/

<dependency>
  <groupId>io.github.openfeign</groupId>
  <artifactId>feign-httpclient</artifactId>
</dependency>

IN application.properties or yaml file 

feign.httpclient.enabled: true


@Configuration
public class FeignClientConfig {

    @Bean
    public CloseableHttpClient feignClient() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(10, TimeUnit.MINUTES);
    connectionManager.setMaxTotal(1000);
    connectionManager.setDefaultMaxPerRoute(20);
     CloseableHttpClient httpClient = HttpClients.custom()
                                                     .setConnectionManager(connectionManager)
                                                     .build()) 
 
     Thread th = new IdleConnectionMonitorThread(connectionManager);
 
     th.start();
    return httpClient;
    }
}

  static class IdleConnectionMonitorThread extends Thread {
 
        private volatile boolean shutdown;
        private PoolingHttpClientConnectionManager connMgr;
 
        public IdleConnectionMonitorThread(PoolingHttpClientConnectionManager connMgr) {
            super();
            this.setName("TCP-Ideal-Monitroing-Thread");
            this.connMgr = connMgr;
        }
 
        @Override
        public void run() {
            try {
                while (!shutdown) {
                        sleep(TimeUnit.MINUTES.toMillis(1));
                        // Close expired connections
                        connMgr.closeExpiredConnections();
                        // Optionally, close connections
                        // that have been idle longer than 60 sec
                        connMgr.closeIdleConnections(10, TimeUnit.MINUTES);
                }
            } catch (InterruptedException ex) {
                // terminate
            }
        }
 
        public void shutdown() {
            shutdown = true;
        }
 
    }
Answer from Bmis13 on Stack Overflow
🌐
Spring Cloud
cloud.spring.io › spring-cloud-netflix › multi › multi_spring-cloud-feign.html
7. Declarative REST Client: Feign
The OkHttpClient and ApacheHttpClient feign clients can be used by setting feign.okhttp.enabled or feign.httpclient.enabled to true, respectively, and having them on the classpath. You can customize the HTTP client used by providing a bean of either ClosableHttpClient when using Apache or OkHttpClient whe using OK HTTP.
🌐
Spring
docs.spring.io › spring-cloud-openfeign › docs › current › reference › html
Spring Cloud OpenFeign
The ones prefixed just with httpclient will work for all the clients, the ones prefixed with httpclient.hc5 to Apache HttpClient 5 and the ones prefixed with httpclient.okhttp to OkHttpClient. You can find a full list of properties you can customise in the appendix. Spring Cloud OpenFeign does not provide the following beans by default for feign, but still looks up beans of these types from the application context to create the feign client:
🌐
GitHub
github.com › OpenFeign › feign
GitHub - OpenFeign/feign: Feign makes writing java http clients easier · GitHub
Feign is a Java to HTTP client binder inspired by Retrofit, JAXRS-2.0, and WebSocket.
Top answer
1 of 1
2

Please refer to the following link on how to customize it. https://codingnconcepts.com/spring-boot/change-default-feign-client-implementation/

<dependency>
  <groupId>io.github.openfeign</groupId>
  <artifactId>feign-httpclient</artifactId>
</dependency>

IN application.properties or yaml file 

feign.httpclient.enabled: true


@Configuration
public class FeignClientConfig {

    @Bean
    public CloseableHttpClient feignClient() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(10, TimeUnit.MINUTES);
    connectionManager.setMaxTotal(1000);
    connectionManager.setDefaultMaxPerRoute(20);
     CloseableHttpClient httpClient = HttpClients.custom()
                                                     .setConnectionManager(connectionManager)
                                                     .build()) 
 
     Thread th = new IdleConnectionMonitorThread(connectionManager);
 
     th.start();
    return httpClient;
    }
}

  static class IdleConnectionMonitorThread extends Thread {
 
        private volatile boolean shutdown;
        private PoolingHttpClientConnectionManager connMgr;
 
        public IdleConnectionMonitorThread(PoolingHttpClientConnectionManager connMgr) {
            super();
            this.setName("TCP-Ideal-Monitroing-Thread");
            this.connMgr = connMgr;
        }
 
        @Override
        public void run() {
            try {
                while (!shutdown) {
                        sleep(TimeUnit.MINUTES.toMillis(1));
                        // Close expired connections
                        connMgr.closeExpiredConnections();
                        // Optionally, close connections
                        // that have been idle longer than 60 sec
                        connMgr.closeIdleConnections(10, TimeUnit.MINUTES);
                }
            } catch (InterruptedException ex) {
                // terminate
            }
        }
 
        public void shutdown() {
            shutdown = true;
        }
 
    }
🌐
Spring Cloud
cloud.spring.io › spring-cloud-openfeign › multi › multi_spring-cloud-feign.html
1. Declarative REST Client: Feign
The OkHttpClient and ApacheHttpClient feign clients can be used by setting feign.okhttp.enabled or feign.httpclient.enabled to true, respectively, and having them on the classpath. You can customize the HTTP client used by providing a bean of either ClosableHttpClient when using Apache or OkHttpClient when using OK HTTP.
Top answer
1 of 3
4

In the bean that we are injecting we have to provide feign.Client's implementation. Simplest is new Client.Default(SSLSocketFactory, HostnameVerifier). I changed the httpClient @Bean injection in code in my question from:

@Bean
    public CloseableHttpClient client() {
 CloseableHttpClient httpClient=null;
         try {
                    //... Skipping code for brevity.  
                    //here creating "sslSocketFactory" used in the HttpClient builder below
                    httpClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
                    .setMaxConnTotal(10)
                    .setMaxConnPerRoute(10)
                    .build();
                
            }catch(IOException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | CertificateException e) {
                System.err.println("Exception during creation of HttpClient. : "+e.getMessage());
            }
        return httpClient;
    }
              

to :

@Bean
    public feign.Client client() {
      
       feign.Client client=null;
        try {

      //... Skipping code for brevity.  
                    //here creating "sslSocketFactory" used in the HttpClient builder below
      client = new Client.Default(sslSocketFactory, new DefaultHostnameVerifier());
            
        }catch(IOException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | CertificateException e) {
            System.err.println("Exception during creation of HttpClient. : "+e.getMessage());
        }
}

Learnings from the experience:

When the documentation says, "You can customize the HTTP client used by providing a bean of either ClosableHttpClient when using Apache or OkHttpClient when using OK HTTP."

And then people say they provided CloseableHttpClient as it is in this question which is not answered properly. The bean injection in this will never work.

On the top of that, the OpenFeign's Github documentation talks about using ApacheHttpClient.

This may leave a person confused. The second part in my question "Other part which I didn't understand, how the Spring was going to hook this custom CloseableHttpClient to Feign as it claims..... the 'client' field in this class is of type feign.Client "

Answer:

There is no magic, what the ApacheHttpClient OpenFeign Github documentation talks about is OpenFeign's wrapper on the Apache's HttpClient library ApacheHttpClient it implements feign.Client interface.

And this ApacheHttpClient implementation is not available in feign core 10.1.1 dependency that comes with Spring Boot starter for openfeign.

2 of 3
3

I've had a struggle with this same problem (although using OkHttpClient instead of ApacheHttpClient). Your question and answer helped me out. Thanks!

The key for me was that in the auto-configuration class (FeignAutoConfiguration) we find the following:

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(OkHttpClient.class)
@ConditionalOnMissingClass("com.netflix.loadbalancer.ILoadBalancer")
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
@ConditionalOnProperty("feign.okhttp.enabled")
protected static class OkHttpFeignConfiguration {

...where this line is of most interest:

@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)

...which effectively makes Spring ignore that configuration when we provide our own http client bean (as stated in the documentation).

What makes this interesting is that the OkHttpFeignConfiguration is itself responsible for the wrapping of the http client in it's own wrapper class (as you state in your own answer):

@Bean
@ConditionalOnMissingBean(Client.class)
public Client feignClient(okhttp3.OkHttpClient client) {
    return new OkHttpClient(client);
}

So, when we do provide our own http client bean, we effectively disable the automatic instantiation of the wrapper. Since Feign does not find a bean of its Client type in the application context it creates one on its own; the Default.Client. Hence, our http client bean is effectively ignored...

The solution for me was to do "the wrapping" myself in the configuration:

@Bean
fun feignClient(client: OkHttpClient) = feign.okhttp.OkHttpClient(client)

When this bean is present in the application context Feign will make use of it rather than creating its default client.

The logic is exactly the same in the ApacheHttpClient case.

The above solution is tested to work for both Feign global configuration and client-specific configuration.

As far as I can tell the documentation says nothing about us having to configure this "wrapper bean" ourself. I might have missed something important, somewhere, or there might have been changes to this beahviour in the latest versions of the library.

🌐
GitHub
github.com › spring-cloud › spring-cloud-openfeign › issues › 98
Feign defaults to DefaultClient when own customized Bean CloseableHttpClient is provided. · Issue #98 · spring-cloud/spring-cloud-openfeign
December 18, 2018 - The OkHttpClient and ApacheHttpClient feign clients can be used by setting feign.okhttp.enabled or feign.httpclient.enabled to true, respectively, and having them on the classpath.
Author: spring-cloud
Find elsewhere
🌐
CodingNConcepts
codingnconcepts.com › spring-boot › feign-apachehttp5-ssl-proxy-connection
ApacheHttp5 FeignClient SSL and Proxy Connection in Spring Boot - Coding N Concepts
September 19, 2021 - package com.example.api; @SpringBootApplication @EnableFeignClients public class ApiApplication { public static void main(String[] args) { SpringApplication.run(ApiApplication.class, args); } } You set feign.httpclient.enabled property to true in application.properties or application.yml file ·
🌐
Maven Repository
mvnrepository.com › artifact › io.github.openfeign › feign-httpclient
Maven Repository: io.github.openfeign » feign-httpclient
1 week ago - Home » io.github.openfeign » feign-httpclient · Feign Apache HttpClient · LicenseApache 2.0 · Tagsclientgithubhttp · Ranking · #2475in MvnRepository · HomePage https://github.com/openfeign/feign 🔍 Inspect URL · Links · 72 versions → · Central (72) 72 versions → ·
Author: OpenFeign
🌐
GitHub
github.com › OpenFeign › feign › blob › master › httpclient › src › main › java › feign › httpclient › ApacheHttpClient.java
feign/httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java at master · OpenFeign/feign
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; · /** * This module directs Feign's http requests to Apache's · * <a href="https://hc.apache.org/httpcomponents-client-ga/">HttpClient</a>. Ex.
Author: OpenFeign
🌐
Reflectoring
reflectoring.io › create-openfeign-http-client
Create an HTTP Client with OpenFeign
October 13, 2023 - It would be much easier and more maintainable to describe the API in a simple, small interface and let Feign interpret and implement that interface at runtime. If we are making HTTP requests in our Java code, and don’t want to write boilerplate code, or use libraries like Apache httpclient directly, Feign is a great choice.
🌐
Javadoc.io
javadoc.io › static › org.springframework.cloud › spring-cloud-openfeign-core › 3.0.2 › org › springframework › cloud › openfeign › FeignAutoConfiguration.HttpClientFeignConfiguration.html
FeignAutoConfiguration.HttpClientFeignConfiguration (Spring Cloud OpenFeign Core 3.0.2 API)
@Configuration(proxyBeanMethods=false) @ConditionalOnClass(value=feign.httpclient.ApacheHttpClient.class) @ConditionalOnMissingBean(value=org.apache.http.impl.client.CloseableHttpClient.class) @ConditionalOnProperty(value="feign.httpclient.enabled", matchIfMissing=true) @Conditional(value=HttpClient5DisabledConditions.class) protected static class FeignAutoConfiguration.HttpClientFeignConfiguration extends Object ·
🌐
Spring Cloud
cloud.spring.io › spring-cloud-openfeign › reference › html
Spring Cloud OpenFeign
The OkHttpClient and ApacheHttpClient feign clients can be used by setting feign.okhttp.enabled or feign.httpclient.enabled to true, respectively, and having them on the classpath. You can customize the HTTP client used by providing a bean of either org.apache.http.impl.client.CloseableHttpClient when using Apache or okhttp3.OkHttpClient when using OK HTTP.
🌐
DeepWiki
deepwiki.com › OpenFeign › feign › 2.1-http-clients
HTTP Clients | OpenFeign/feign | DeepWiki
April 18, 2025 - Sources: core/src/test/java/feign/client/DefaultClientTest.java37-179 okhttp/src/test/java/feign/okhttp/OkHttpClientTest.java38-149 httpclient/src/test/java/feign/httpclient/ApacheHttpClientTest.java39-123 java11/src/test/java/feign/http2client/test/Http2ClientTest.java41-316 · All client implementations support custom SSL configuration: Sources: core/src/main/java/feign/Client.java83-105 core/src/test/java/feign/client/DefaultClientTest.java133-141 · The clients handle request bodies differently: Default Client: Controls if request buffering is enabled/disabled ·
🌐
Spring Cloud
cloud.spring.io › spring-cloud-openfeign › reference › html › appendix.html
Appendix A: Common application properties
Various properties can be specified inside your application.properties file, inside your application.yml file, or as command line switches. This appendix provides a list of common Spring Cloud OpenFeign properties and references to the underlying classes that consume them · feign.client.d...
🌐
Medium
medium.com › @AlexanderObregon › navigating-client-server-communication-with-springs-feignclient-annotation-70376157cefd
Navigating Client-Server Communication with Spring’s @FeignClient Annotation
March 30, 2026 - By adding @EnableFeignClients, you're telling Spring to scan for interfaces that are annotated with @FeignClient and to generate proxy implementations for them.