gpt4 book ai didi

java - 如何在 Spring Boot 应用程序中从 linux 文件系统(而不是类路径)加载信任库

转载 作者:行者123 更新时间:2023-12-04 22:41:47 33 4
gpt4 key购买 nike

我无法使用以下方法加载信任存储文件,

  @Value("${app.ssl.trust-store}")
private Resource trustStore;
@Bean("restTemplateForCustom")
public RestTemplate restTemplateForCustom(final RestTemplateBuilder builder)
throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException,
CertificateException, IOException {
final SSLContext sslContext =
new SSLContextBuilder().loadTrustMaterial(trustStore.getFile(), trustStorePass).build();
return new RestTemplateBuilder().build();
}
即使我尝试了以下方法
@Value("${app.ssl.trust-store}")
private Resource trustStore;
@Bean("restTemplateForCustom")
public RestTemplate restTemplateForCustom(final RestTemplateBuilder builder)
throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException,
CertificateException, IOException {
final SSLContext sslContext =
new SSLContextBuilder().loadTrustMaterial(trustStore.getURL(), trustStorePass).build();
return new RestTemplateBuilder().build();
}
尝试使用以下行传递文件,
-Dapp.ssl.trust-store=/config/truststore.p12
异常(exception):
java.io.FileNotFoundException: /tmp/tomcat-docbase.8080.1011071379153590118/config/truststore.p12 (No such file or directory)
预期:
我有来自同一个 jar 位置的配置文件夹,并试图从文件系统中选择 keystore ,但它来自 tmp。为什么请帮忙。

最佳答案

loadTrustMaterial方法使用 URL 加载信任库文件,因此您需要提供完全限定的 URL。
因此,将信任库文件提供为 file:///config/truststore.p12而不是 /config/truststore.p12 .
所以,你的 JVM 参数应该是这样的:

-Dapp.ssl.trust-store=file:///config/truststore.p12

关于java - 如何在 Spring Boot 应用程序中从 linux 文件系统(而不是类路径)加载信任库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70034317/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com