方式一
@Configuration
public class FeignConfiguration {
@Bean
public Client feignClient(CachingSpringLoadBalancerFactory cachingFactory, SpringClientFactory clientFactory) {
return new LoadBalancerFeignClient(new Client.Default(getSSLSocketFactory(), new NoopHostnameVerifier()),
cachingFactory, clientFactory);
}
private SSLSocketFactory getSSLSocketFactory() {
try {
return SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build().getSocketFactory();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
方式二(okhttp )
@Configuration
public class FeignConfiguration {
@Bean
public Client feignClient(CachingSpringLoadBalancerFactory cachingFactory, SpringClientFactory clientFactory) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
return new LoadBalancerFeignClient(new OkHttpClient(new okhttp3.OkHttpClient()
.newBuilder()
.sslSocketFactory(OkHttpUtils.getIgnoreInitedSslContext().getSocketFactory(), OkHttpUtils.IGNORE_SSL_TRUST_MANAGER_X509)
.hostnameVerifier(OkHttpUtils.getIgnoreSslHostnameVerifier())
.build()),
cachingFactory, clientFactory);
}
}