简体   繁体   English

如何在 spring application.properties 中指定我的 ssl 密钥库文件的本地文件路径?

[英]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:当我进行这些更改时,这对我有用:

  1. Set tomcat's version to 8.5.20将tomcat的版本设置为8.5.20
  2. Changed the property to : file:path将属性更改为:file:path

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.

相关问题 如何在 Spring Boot 应用程序的 application.properties 文件中设置 MyBatis 配置属性? - How do I set MyBatis configuration properties in an application.properties file in a Spring Boot application? 我应该如何为Spring创建一个Java application.properties文件? - How should I create a Java application.properties file for Spring? 如何更改我的application.properties文件? - How I can change my application.properties file? Spring Boot 获取 application.properties 的实例(或其文件路径) - Spring Boot get istance of application.properties (or its file path) 春季启动:从“ application.properties”读取文件路径 - Spring boot: Read a file PATH from “application.properties” 如何在spring boot中将创建的文件保存到application.properties文件中指定的路径 - how to save created file to path specified in application.properties file in spring boot 在应用程序属性弹簧文件中指定相对路径 - Specify a relative path in application properties spring file 如何在 spring 应用程序中动态修改 application.properties 文件? - How to Modify application.properties file dynamically in spring application? "如何在 application.properties 文件中的 Spring Boot 应用程序中配置 HikariCP?" - How do I configure HikariCP in my Spring Boot app in my application.properties files? 如何在另一个路径中加载application.properties文件? - How to load application.properties file in another path?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM