Feign HTTPS 关闭SSL证书验证

本文介绍了如何在Feign客户端中配置SSL,包括通过添加feign-httpclient依赖来禁用SSL验证,以及使用启动参数和自定义Client配置来实现相同目的。同时提供了启用Okhttp的方式和相关依赖。这些方法对于在不信任的环境中进行HTTPS通信很有帮助。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方式一:
添加feign-httpclient依赖:

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

如果是使用 okhttp,则必须使用另一个应用程序属性启用 okhttp 并添加 feign-okhttp 依赖项

feign.httpclient.disableSslValidation=true
feign.httpclient.enabled=false
feign.okhttp.enabled=true
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-okhttp</artifactId>
</dependency>

方式二:
eign.httpclient.disableSslValidation = true 不起作用的话:
启动参数:

-Dfeign.httpclient.disableSslValidation=true

方式三:

public class ClientConfiguration {

    @Bean
    public Client feignClient() {
        return new Client.Default(getSSLSocketFactory(), new NoopHostnameVerifier());
    }

    private SSLSocketFactory getSSLSocketFactory() {
        try {
            SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
            return sslContext.getSocketFactory();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值