In the Spring Boot project, using RestTemplate to call the https interface appears unable to find valid certification path to requested target

Problem description: The following error occurred when using RestTemplate to call https interface in Spring Boot project:

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

Solution: The reason for the above problem is that the security certificate that comes with Java is not trusted. The implementation in the code is to ignore the certificate when building the restTemplate and bypass the SSL verification.

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

Guess you like

Origin blog.csdn.net/y_bccl27/article/details/111358091