java - 如何在服务器 Spring Boot 应用程序中获取附加的自签名证书
问题描述
我的客户端我已在下面的 restTemplate 代码中附加了证书。使用这个休息模板我正在调用其他 API(服务器端)。如何在该服务器端获取证书
@Bean(name="custRest")
@Primary
public RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception {
char[] password = "changeit".toCharArray();
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = SSLContextBuilder
.create().loadKeyMaterial(new File("C:\\java\\java-certificate.der"),null,null)
.loadTrustMaterial(ResourceUtils.getFile("C:\\java\\java-certificate.der"), null,
acceptingTrustStrategy)
.build();
HttpClient client = HttpClients.custom().setSSLContext(sslContext).build();
return builder.requestFactory(new HttpComponentsClientHttpRequestFactory(client))
.build();
}
解决方案
您可以在文章中找到为 Spring Boot 配置 HTTPS 的所有步骤: https ://www.baeldung.com/spring-boot-https-self-signed-certificate
推荐阅读
- c# - 如何使我的机器人列表服务器位于其中?
- c++ - 初始化列表初始化的类 std::array 成员变量
- arrays - Swift 是否有任何简单的方法来获取二维数组中的列?
- java - 通过 Spring Boot 调用 AirTable Rest API 返回 401
- python - 如何将一个变量值嵌入到另一个变量中?
- android - 无法在 Fragment 的 onCreateView 方法中更改 TextView 的文本
- excel - 从 VBA 类中的数组成员中获取对象
- powerbi - 按国家/地区划分的节假日 Power BI 工作时数
- javascript - 多个请求之间有 for 循环和超时
- r - 水平出现频率的下降因子