I am trying to enable SSL for my Spring Boot application for testing purposes. I generated a keystore file with this command line:
keytool -genkey -alias tomcat
-storetype PKCS12 -keyalg RSA -keysize 2048
-keystore keystore.p12 -validity 3650
And added the configuration below to my application.properties file:
server.port=8443
server.ssl.key-store: keystore.p12
server.ssl.key-store-password: mypassword
server.ssl.keyStoreType: PKCS12
server.ssl.keyAlias: tomcat
When I run the application with an embedded Tomcat 8 version, SSL is enabled successfully with no errors during the building process.
But when I run it with an embedded Tomcat 7 version through changing the pom.xml file as follows:
<properties>
<tomcat.version>7.0.65</tomcat.version>
</properties>
SSL doesn't get enabled and I am met with these errors:
java.io.FileNotFoundException: /tmp/tomcat.4863947968145457153.8443/file:/home/yahyaharif/spring-workspace/demossl/keystore.p12 (No such file or directory)
org.apache.catalina.LifecycleException: Failed to start component [Connector[org.apache.coyote.http11.Http11NioProtocol-8443]]
org.springframework.boot.context.embedded.EmbeddedServletContainerExcepti> on: Unable to start embedded Tomcat servlet container
I've looked up the errors and I noticed that I need to add an embedded servlet container bean to my main, but to no avail.
I also made sure the file path for the keystore file was correct.
ANy lead on why SSL is enabled flawlessly on an embedded Tomcat 8 and not on an embedded Tomcat 7?
Another way to change the port of embedded tomcat in the Spring Boot application is by specifying the server. port property in the resource file. For example, if you want your Spring boot application to listen on port 8080, then you can specify server. port=8080 on the application.
When we create an application deployable, we would embed the server (for example, tomcat) inside the deployable. For example, for a Spring Boot Application, you can generate an application jar which contains Embedded Tomcat. You can run a web application as a normal Java application!
A change was made in Tomcat 8 to allow a keystore to be loaded from within an embedded jar file. It's been backported to Tomcat 7 but won't be available until 7.0.66 is released
If you try to use a version of Spring Boot that expects this change to be there (1.2.7 or later), it will fail if it's not. I think you have two options until Tomcat 7.0.66 is released:
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