我使用ssl支持构建spring-boot可执行文件war。 我的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'
答案 0 :(得分:9)
更新:由于this enhancement request,下面描述的限制不再适用。 Tomcat 8.0.28+和7.0.66+可以从jar文件中加载密钥库。
我猜你使用Tomcat作为嵌入式servlet容器?作为noted in the reference documentation,Tomcat目前不支持从jar中加载密钥库或信任库:
Tomcat要求密钥存储区(以及信任存储区,如果您使用的话)可以在文件系统上直接访问,即无法从jar文件中读取它。
您应该将public Task[] StartProcessing()
{
...
for (int i = 0; i < jobList.Count(); i++)
{
tasks[i] = ProcessJob(jobList[i]);
}
...
return tasks;
}
//in the MAIN METHOD of your application/process
var tasks = new SomeMainClass().StartProcessing();
// do all other stuffs here, and just at the end of process
Task.WaitAll(tasks);
移出您的jar并更新keystore.jks
及其在文件系统上的位置。
答案 1 :(得分:2)
在我的Spring Boot应用程序中,我通过将/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
文件放入资源文件夹解决了此问题。
答案 2 :(得分:0)
1- Generate JKS
jmendoza@jmendoza:~$ keytool -genkey -alias selfsigned_localhost_sslserver -keyalg RSA -keysize 2048 -validity 700 -keypass changeit -storepass changeit -keystore ssl-server.jks
2- Config JKS in application.properties
server.port=8081
server.ssl.key-alias=selfsigned_localhost_sslserver
server.ssl.key-password=changeit
server.ssl.key-store=/home/jmendoza/IdeaProjects/dummy/config/ssl-server.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=JKS
3- Invoke service from postman
https://localhost:8081/api/process
Note: For postman remember, Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General