I am using Spring boot 1.2.7 for my application and as a requirement I have to load the SSL cert from classpath. So, I added my PKCS12 file in my classpath and used following code (in AppInitializer
class to load it:
final String sslKeystoreFilepath = this.getClass().getClassLoader().getResource(sslKeystoreFilename).getFile();
I am noticing two things here:
The string contains file:
in it. If I run the same code through a plain standalone program with main
method, I couldn't see anything like file:
.
When I run the Spring boot app (using generated fat jar), it throws exception saying:
SEVERE: Failed to load keystore type PKCS12 with path /Users/my_user/Projects/my_app/build/libs/myapp-1.0-SNAPSHOT-dev.jar!/dev_keystore.p12 due to /Users/my_user/Projects/my_app/build/libs/myapp-1.0-SNAPSHOT-dev.jar!/dev_keystore.p12 (No such file or directory)
java.io.FileNotFoundException: /Users/my_user/Projects/my_app/build/libs/myapp-1.0-SNAPSHOT-dev.jar!/dev_keystore.p12 (No such file or directory)
What am I doing wrong?
You need to use file:// . FileNotFoundException: C:\Windows\Temp\tomcat. 8707914234839952642.1111\file:\c:\path\to\file\keystore.
Spring Boot has a complete Tomcat inside. It builds a so-called fat-jar with everything needed inside. You don't need Tomcat installed in your system. BTW: Spring Boot also supports other application servers like Jetty.
I think you can add this configuration in your .properties file as belows, rather than getting the string,
server.ssl.key-store: classpath:dev_keystore.p12
server.ssl.key-store-password: mypassword
server.ssl.keyStoreType: PKCS12
server.ssl.keyAlias: tomcat
If you need to do what you are doing now, let me know, I will give that answer
In this answer seems that Tomcat can't read the keystore conatined in a jar, but I'm not sure of that because I use Spring Boot 1.2.5 and everything works like a charme with the keystore in the classpath. However I've exactly the same error of yours when I try to upgrade to Spring Boot 1.2.7 and above, so I concluded that depends on Spring Boot. At this time, I downgraded to 1.2.5 version. :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With