英文:
Invalid path of external Kafka keystore and truststore
问题
以下是您要翻译的内容:
我的应用连接到Kafka主题,在本地环境中,当truststore和keystore存储在类路径下时,一切正常。但是,当我尝试切换到部署在Docker容器中的外部环境,并指向存储在服务器上的这些文件时,应用程序崩溃了。
在本地环境中的代码片段,它可以正常工作:
spring.kafka.ssl.trust-store-location=file:src/main/resources/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=file:src/main/resources/keys/application.keystore.jks
在服务器端的application.properties代码片段,应用程序在Docker容器内启动时无法工作。两个密钥存储在容器内的/deployment/keys
文件夹中:
spring.kafka.ssl.trust-store-location=/deployment/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=/deployment/keys/application.keystore.jks
出现了以下Java异常:
NoSuchFileException: /tmp/tomcat-docbase.45456574985379.8080/deployment/keys/application.keystore.jks
因此,出于未知的原因,Docker容器内的Spring Boot在keystore和truststore位置前添加了/tmp/tomcat-docbase.45456574985379.8080/
前缀。
我还尝试过:
spring.kafka.ssl.trust-store-location=file:/deployment/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=file:/deployment/keys/application.keystore.jks
和
spring.kafka.ssl.trust-store-location=file:///deployment/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=file:///deployment/keys/application.keystore.jks
但是似乎都不起作用。我不想更改代码,但我想到的是创建一个Properties对象,并使用这些路径创建字符串。然后将它们作为bean注入KafkaTemplate。然而,我还没有检查过这是否有帮助。我更愿意仅关注调整application.properties文件,而不是修正代码。您能帮助我找到解决方案吗?
英文:
My app connects to Kafka topic and everything goes well in local environment when truststore and keystore are stored under classpath, but when I try to switch to Dockerized external environment and point to those files localized on a server, then the app crashes.
Snippet in a local environment where it works:
spring.kafka.ssl.trust-store-location=file:src/main/resources/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=file:src/main/resources/keys/application.keystore.jks
Snippet of application.properties on a server side when the app is launched inside a docker container and does not work. Both keys are stored in /deployment/keys
folder inside the container:
spring.kafka.ssl.trust-store-location=/deployment/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=/deployment/keys/application.keystore.jks
The following java exception occurs:
NoSuchFileException: /tmp/tomcat-docbase.45456574985379.8080/deployment/keys/application.keystore.jks
So for an unknown reason Spring Boot inside Docker container adds the /tmp/tomcat-docbase.45456574985379.8080/
prefix to the keystore and truststore location.
I have also tried:
spring.kafka.ssl.trust-store-location=file:/deployment/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=file:/deployment/keys/application.keystore.jks
and
spring.kafka.ssl.trust-store-location=file:///deployment/keys/application.truststore.jks
spring.kafka.ssl.key-store-location=file:///deployment/keys/application.keystore.jks
but none of them seem to work. I would not like to change the code but what comes to my mind is to create a Properties object and create strings with those paths. Then inject them to the KafkaTemplate as a bean. However, I have not yet checked if this could help. Would rather focus just on adjusting application.properties file than correct the code. Could you please help me find the solution?
专注分享java语言的经验与见解,让所有开发者获益!
评论