Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧靴/防波堤&x2B;SSL:找不到密钥库(FileNotFoundException)_Java_Spring Boot_Ssl_Keystore_Embedded Jetty - Fatal编程技术网

Java 弹簧靴/防波堤&x2B;SSL:找不到密钥库(FileNotFoundException)

Java 弹簧靴/防波堤&x2B;SSL:找不到密钥库(FileNotFoundException),java,spring-boot,ssl,keystore,embedded-jetty,Java,Spring Boot,Ssl,Keystore,Embedded Jetty,我试图在Spring引导应用程序中使用嵌入式jetty启用SSL 弹簧启动启动器版本:2.1.0.发布 我的配置: 我使用以下命令创建了一个密钥库: keytool -genkey -keyalg RSA -alias webapp -keystore keystore.jks -storepass password -keysize 2048 生成的keystore.jks文件位于src/main/resources/ssl中 教程大多说,在应用程序.yaml中引用此密钥库应该足以“使其工作

我试图在Spring引导应用程序中使用嵌入式jetty启用SSL

弹簧启动启动器版本:2.1.0.发布

我的配置:

我使用以下命令创建了一个密钥库:

keytool -genkey -keyalg RSA -alias webapp -keystore keystore.jks -storepass password -keysize 2048
生成的keystore.jks文件位于
src/main/resources/ssl

教程大多说,在应用程序.yaml中引用此密钥库应该足以“使其工作”:

错误:

当我尝试启动应用程序时,它失败:

Caused by: org.springframework.boot.web.server.WebServerException: Could not find key store 'classpath:keystore.jks'
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSslKeyStore(SslServerCustomizer.java:195) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSsl(SslServerCustomizer.java:164) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.customize(SslServerCustomizer.java:73) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.customizeSsl(JettyServletWebServerFactory.java:195) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:145) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 13 common frames omitted
    Caused by: java.io.FileNotFoundException: class path resource [keystore.jks] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSslKeyStore(SslServerCustomizer.java:190) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 19 common frames omitted
但是,当我查看maven目标目录时,keystore.jks放在classes/ssl下,所以它应该在classpath中,对吗

有人能指出我遗漏了什么吗

编辑:


奇怪的是,将keystore.jks移动到
src/main/resources
似乎解决了这个问题。为什么jetty能够在那里找到密钥库,但不能在子目录
src/main/resources/ssl

默认情况下,类路径设置为
src/main/resources
。这意味着如果您的
子目录中有
,则需要指定
jks文件的完整路径


密钥存储:classpath:ssl/keystore.jks

您是否尝试了
java-jar$JETTY\u HOME/start.jar--列出类路径
以获取类路径我以前遇到过这个问题,看起来是个糟糕的实现。您可以尝试使用文件keystore.jks来代替传递类路径,但即使这样也不行。您可以在其中调试并查看!正如您所提到的,最好的选择是将其保存在resources文件夹中。在这方面花了很多时间,最后继续节省资源。顺便说一句,这不是码头问题,tomcat也有同样的问题。
Caused by: org.springframework.boot.web.server.WebServerException: Could not find key store 'classpath:keystore.jks'
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSslKeyStore(SslServerCustomizer.java:195) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSsl(SslServerCustomizer.java:164) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.customize(SslServerCustomizer.java:73) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.customizeSsl(JettyServletWebServerFactory.java:195) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:145) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 13 common frames omitted
    Caused by: java.io.FileNotFoundException: class path resource [keystore.jks] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSslKeyStore(SslServerCustomizer.java:190) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 19 common frames omitted