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

问题描述: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

你可能感兴趣的:(Spring,Boot)