Spring Java应用程序找不到密钥库文件 [英] Spring Java app not finding the keystore file

查看:60
本文介绍了Spring Java应用程序找不到密钥库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个简单的Spring应用程序以使用SSL并将其托管在Digital Ocean上.为什么我的应用程序找不到密钥库文件?

I am trying to set up a simple Spring application to use SSL and host it on Digital Ocean. Why is my app not finding the keystore file?

我设置的Droplet是基于Ubuntu 18.04的.我使用Letsencrypt来获取证书,并指南来生成PKCS文件.我已经将application.properties文件设置为在jar文件的当前目录中查找,如下所示:

The droplet I've set up is based on Ubuntu 18.04. I used Letsencrypt to get a certificate and this guide to generate a PKCS file. I've set up my application.properties file to look in the jar file's current directory like so:

security.require-ssl:true
server.ssl.key-store:keystore.p12
server.ssl.key-store-password:<password>
server.ssl.key-store-type:PKCS12
server.ssl.key-alias:<alias>

我希望它可以在配置的端口上运行并启动Web服务器.但是,我在堆栈跟踪中得到的是:

I would expect this to run and start a web server on the configured port. However, what I get in the stack trace is this:

Caused by: java.io.FileNotFoundException: /root/software/gimmememe/target/keystore.p12  (No such file or directory)

奇怪的是,当我在自己的Windows计算机上使用相同的keystore.p12文件运行相同的jar时,它运行良好:

Weirdly enough when I run the same jar with the same keystore.p12 file on my own Windows machine it runs fine:

o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9123 (https) with context path ''
meme.Application                         : Started Application in 4.985 seconds (JVM running for 5.464)

我认为这不是Ubuntu计算机上的权限问题,因为我尝试像这样设置密钥库文件的权限:

I don't think it's a permissions issue on the Ubuntu machine as I tried setting the permissions on the keystore file like so:

-rw-r--r-- 1 root root     4274 Mar 26 18:44 keystore.p12

我正在使用以下命令运行jar文件(也尝试使用sudo infront):

I am running my jar file with the following command (tried with sudo infront as well):

java -jar gimme-meme-1.0.0.war

推荐答案

Spring会从类路径中加载文件,这允许,因此您应在路径前添加该 classpath:,例如

Spring loads the file from the classpath, which allows, so you should prefix the path with that classpath:, e.g.

server.ssl.key-store : classpath:keystore.p12

或者如果您使用 = 符号作为键/值定界符:

Or if you use the = symbol as a key/value delimiter:

server.ssl.key-store = classpath:keystore.p12

请记住,该值仅在左侧修剪,因此该值后不能有任何尾随空白.

Bear in mind that the value is only trimmed on the left side, so you can not have any trailing whitespace after the value.

这篇关于Spring Java应用程序找不到密钥库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆