yahyaharif
yahyaharif

Reputation: 170

Enabling SSL in Spring Boot with an embedded Tomcat 7 - FileNotFoundException and o.a.coyote.http11.Http11NioProtocol issue

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?

Upvotes: 5

Views: 2491

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116091

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:

  • Use Tomcat 8
  • Use Tomcat 7 with Spring Boot 1.2.6 or earlier

Upvotes: 5

Related Questions