原始问题发布在这里:Spring Boot SSL Client
jonashackt提供了一个解决方案(如下所示)。它可以在我的实验室上正常工作。但是,当我将其部署为Openshift(AWS)的微服务时,找不到keystore.jks和tructstore.jks。我将这两个文件放在src / main / resources /下。
有人知道吗?提前非常感谢您!
jonashackt的解决方案
@Configuration
public class RestClientCertTestConfiguration {
private String allPassword = "allpassword";
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception {
SSLContext sslContext = SSLContextBuilder
.create()
.loadKeyMaterial(ResourceUtils.getFile("classpath:keystore.jks"), allPassword.toCharArray(), allPassword.toCharArray())
.loadTrustMaterial(ResourceUtils.getFile("classpath:truststore.jks"), allPassword.toCharArray())
.build();
HttpClient client = HttpClients.custom()
.setSSLContext(sslContext)
.build();
return builder
.requestFactory(new HttpComponentsClientHttpRequestFactory(client))
.build();
}
}