我构建了带有 ssl 支持的 spring-boot 可执行战争。我的 application.properties 文件是:
server.port = 8443
server.ssl.key-store = classpath:keystore.jks
server.ssl.key-store-password = secret
server.ssl.key-password = another-secret
WAR 文件包含“keystore.jks”文件。但我得到了奇怪的例外:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Could not find key store classpath:keystore.jks
Caused by: java.io.FileNotFoundException: class path resource [keystore.jks] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/D:/projects/vi3na/vi3na.web/target/vi3na.war!/WEB-INF/classes!/keystore.jks
什么标志’!’在路径’D:/projects/vi3na/vi3na.web/target/vi3na.war!/WEB-INF/classes!/keystore.jks’中的意思
原文由 Igor Tytar 发布,翻译遵循 CC BY-SA 4.0 许可协议
更新: 由于 此增强请求,下面描述的限制不再适用。 Tomcat 8.0.28+ 和 7.0.66+ 可以从 jar 文件中加载密钥库。
原始答案
我猜您使用 Tomcat 作为嵌入式 servlet 容器?如 参考文档中所述,Tomcat 目前不支持从 jar 中加载密钥库或信任库:
您应该将
keystore.jks
从 jar 中移出并更新server.ssl.key-store
及其在文件系统上的位置。