我如何使用 spring kafka(没有 sboot)进行 SSL 配置,例如用于指定信任库位置的相对/类路径?
仅在提供绝对路径时有效。
令人惊讶的是,当使用 spring boot 运行时,它与相对路径(在 jar 内)一起工作..
最佳答案
该文件由 Kafka 读取,而不是 Spring。
Kafka 不了解 Spring 的类路径资源抽象。
我认为你对引导有误;它只有在 jar 爆炸时才有效; boot 在 KafkaProperties
...
map.from(this::getTrustStoreLocation).as(this::resourceToPath)
.to(properties.in(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG));
...
private String resourceToPath(Resource resource) {
try {
return resource.getFile().getAbsolutePath();
}
catch (IOException ex) {
throw new IllegalStateException(
"Resource '" + resource + "' must be on a file system", ex);
}
}
要在 jar 中使用信任库,您需要先将其复制到文件系统(例如 /tmp
),然后再启动应用程序上下文。
关于java - spring kafka ssl 类路径信任库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53437352/