[英]How do I specify local file path to my ssl keystore file in spring application.properties?
Given I have file in c:\\path\\to\\file\\keystore.jks
鉴于我在
c:\\path\\to\\file\\keystore.jks
and my application.properties file contains server.ssl.key-store=c:\\path\\to\\file\\keystore.jks
我的 application.properties 文件包含
server.ssl.key-store=c:\\path\\to\\file\\keystore.jks
I get the following exception java.io.FileNotFoundException: C:\\Windows\\Temp\\tomcat.2910824355292831382\\file:\\c:\\path\\to\\file\\keystore.jks (The filename, directory name, or volume label syntax is incorrect)
我收到以下异常
java.io.FileNotFoundException: C:\\Windows\\Temp\\tomcat.2910824355292831382\\file:\\c:\\path\\to\\file\\keystore.jks (The filename, directory name, or volume label syntax is incorrect)
What is the correct way to specify the path?指定路径的正确方法是什么?
Do not rely on absolute paths.不要依赖绝对路径。 Put the file into same directory as Spring Boot JAR and add this line into your application.properties:
将文件放入与 Spring Boot JAR 相同的目录中,并将此行添加到您的 application.properties 中:
server.ssl.key-store=file:keystore.jks
Second option is to pass system variable to -Dserver.ssl.key-store=file:keystore.jks
第二个选项是将系统变量传递给
-Dserver.ssl.key-store=file:keystore.jks
Below worked for me with Tomcat 8.5.2:下面使用 Tomcat 8.5.2 为我工作:
Windows:窗户:
server:
ssl:
key-store: file:C:\<complete file path with extension>
Linux: Linux:
server:
ssl:
key-store: file:/J2EE/<complete file path with extension>
This worked for me when I made these changes:当我进行这些更改时,这对我有用:
Check which version of tomcat is being used by spring boot.检查 spring boot 正在使用哪个版本的 tomcat。 According to this github issue tomcat versions less than 7.0.66 relativize the server.ssl.key-store setting.
根据这个 github issue低于 7.0.66 的 tomcat 版本相对化 server.ssl.key-store 设置。
Putting file:
didn't work for relative paths for me.放置
file:
对我来说不适用于相对路径。 In summary:总之:
If you put the keystore in your resources, you do this:如果您将密钥库放在您的资源中,您可以这样做:
key-store: classpath:keystore.jks
However, if you try this:但是,如果您尝试这样做:
key-store: file:keystore.jks
you will get:你会得到:
java.lang.IllegalStateException: no valid keystore
So, instead, just do this:所以,相反,只需这样做:
key-store: keystore.jks
Strangely, if you supply the full path (not relative path), then file:
will still work.奇怪的是,如果您提供完整路径(不是相对路径),那么
file:
仍然有效。
Just use quotes for keystore file path只需对密钥库文件路径使用引号
server:
port: 8443
ssl:
enabled: true
key-store: "/path/to/keystore/keystore.jks"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.