背景:localhost調平安的ekyc接口,網絡的關係需要添加代理才能成功,而且我們堅持要用feignClient來做接口調用,於是最後只能給FeignClient加網絡代理了,但uat的測試場和PROD是不需要這麽做的,所以通過配置開關來實現動態的創建PingAnRemoteService(feignClient)的bean
貼代碼:
import feign.Feign;
import okhttp3.OkHttpClient;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import java.net.InetSocketAddress;
import java.net.Proxy;
public class FeignClientUtils {
public static PingAnRemoteService buildPingAnFeignClientWithProxy(){
ApplicationParam appParam = SpringUtil.getAppContext().getBean(ApplicationParam.class);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(appParam.getProxyHost(), Integer.valueOf(appParam.getProxyPort())));
OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient okHttpClient = new OkHttpClie