Feign客户端组件配置

Feign中默认使用JDK原生测URLConnection发送HTTO请求,我们可以集成别的组件来替换掉URLConnection,比如HttpClient或者OkHttp

配置OkHttp首先需要加入OkHttp依赖

        
        
            io.github.openfeign
            feign-okhttp
        

然后修改配置,将Feign的HttpClient禁用,启用OkHttp。在application.yml中配置

feign:
  httpclient:
    enabled: false
  okhttp:
    enabled: true

 

下面是OkHttp自动配置源码

import feign.Client;
import feign.okhttp.OkHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.Condit

你可能感兴趣的:(微服务,java)