I use Spring Boot 1.4.0. And I find that tomcat can't read the keystore conatined in a jar. But how can I load the keystore in a jar.
The configuration about SSL:
server:
port: 8443
ssl:
enabled: true
key-store: classpath:keystore.jks
key-store-password: pass
key-alias: pass
#protocol: TSL
enabled-protocols: TLSv1,TLSv1.1,TLSv1.2
The Exception:
java.io.FileNotFoundException: class path resource [xx.jks] cannot be resolved to absolute file path because it does not reside in the file system:jar:file:/C:/xx/xx/xx/xx/xx/target/xx-1.0-SNAPSHOT.jar!/xx.jks
This works fine in our Tomcat SSL sample. Please try with the latest 1.4.x release (1.4.6.RELEASE) and, if that doesn't help, please provide a small sample that reproduces the problem.
it works fine in IntelliJ IDEA. If I build it as a jar and run this jar, it will show this Exception
it works fine in IntelliJ IDEA. If I build it as a jar and run this jar. It will show this Exception
I already understood that from your original description when you said it can't read the keystore from a jar file. As I said above, it works fine in our sample so we're going to need to see a sample from you that reproduces the problem.
Thanks. I fixed it by your samples.
@wilkinsona
I'm facing the same problem and I've already followed your SSL sample but it doesn't work for me.
In elicpse it works fine but if I build its as a JAR then it will throw an exception.
Properties:
server.port=1019
server.ssl.enabled=true
server.ssl.key-alias=springboot_pk
server.ssl.key-store-type=JKS
server.ssl.key-password=springboot
server.ssl.key-store=classpath:springboot.JKS
Exception:
elling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Could not load key store: class path resource [springboot.JKS] cannot be resolved to URL because it does not exist
2018-10-31 11:10:05.823 INFO 9736 --- [ main] ConditionEvaluationReportLoggingListener
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-10-31 11:10:05.829 ERROR 9736 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Could not load key store: class path resource [springboot.JKS] cannot be resolved to URL because it does not exist
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
@GursharanKhalsa Please see my comments above. If you鈥檇 like someone to spend some time trying to help you, please provide a small sample that reproduces the problem. Before doing that, I鈥檇 check that you have a file named springboot.JKS (with matching case) in src/main/resources.
@wilkinsona Thanks for the reply but this problem occur because of classpath resource when I run in eclipse it would easily find the .jks file but after building the project into single.jar. The .jks file would not find as a classpath resource so I resolved it by replacing classpath:springboot.jks to ./springboot.jks and place .jks file parallel to.jar file and it worked.
But I would like to know about if we add some required resources insrc/main/resources parallel to application.properties then why spring throws these kinds of exceptions at runtime after build and What is an appropriate solution to add the resources which we need at runtime?
@GursharanKhalsa Loading a keystore from a jar file should work. As I鈥檝e already said above, if you鈥檇 like someone to spend some time trying to help you, please provide a small sample that reproduces the problem.
Hi
While enabling HTTPS for spring boot project i am getting like this please need help
Caused by: org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException: Connector configured to listen on port 8477 failed to start
my ssl configuration
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:server_hce.p12
server.ssl.key-store-password=domain
server.ssl.key-alias=domain
security.require-ssl=true
server.ssl.enabled=true
server.port=8477
http.port=8442
need help please
@Pmenasigi If you're looking for some help, please ask on Gitter or Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
@wilkinsona Thanks for the reply but this problem occur because of classpath resource when I run in eclipse it would easily find the .jks file but after building the project into single.jar. The .jks file would not find as a classpath resource so I resolved it by replacing
classpath:springboot.jksto./springboot.jksand place.jksfile parallel to.jarfile and it worked.But I would like to know about if we add some required resources in
src/main/resourcesparallel to application.properties then why spring throws these kinds of exceptions at runtime after build and What is an appropriate solution to add the resources which we need at runtime?
I am also facing the same issue
I think it is a bit more general problem, try to load a resource from a spring boot jar as an URL instead of a File. Like this way:
@Value("${server.ssl.key-store}")
private Resource keyStore;
Then later:
keyStore.getURL()