Spring Boot项目中使用RestTemplate调用https接口出现 unable to find valid certification path to requested target

在Spring Boot项目中,使用RestTemplate调用https接口时遇到'unable to find valid certification path to requested target'错误。解决方法是通过忽略证书并绕过SSL验证来构建RestTemplate。通过在代码中设置静态方法调用RestTemplate,可以成功避免该问题。
摘要由CSDN通过智能技术生成

问题描述:Spring Boot项目中使用RestTemplate调用https接口出现以下错误:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

解决方法:出现上述问题的原因就是Java自带的安全证书不受信任,在代码里面的实现方式为在构建restTemplate时忽略证书,绕开SSL验证

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值