Unable to run Spring boot application using SSL

Viewed 1045

I am unable to run a spring boot application with https. I know that Spring boot uses an embedded tomcat server

below is the stacktrace

org.apache.catalina.LifecycleException: Protocol handler start failed
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1008) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:227) [tomcat-embed-core-9.0.26.jar!/:9.0.26]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:263) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:195) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:297) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) [spring-context-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
    at com.leapanalysis.apis.application.LAApplication.main(LAApplication.java:33) [classes!/:0-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_222]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_222]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [apis.jar:0-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [apis.jar:0-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [apis.jar:0-SNAPSHOT]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [apis.jar:0-SNAPSHOT]
 but has failed to stop it. This is very likely to create a memory leak. Stack trace of
APPLICATION FAILED TO START
Description
The Tomcat connector configured to listen on port 8181 failed to start. The port may already be in use or the connector may be misconfigured.
Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8181, or configure this application to listen on another port.

Below shown is my Yaml file

server:
  port: 8181
  ssl:
    enabled: true
    key-alias: tomcat
    key-password: tomcat
    key-store-password: tomcat
    key-store: classpath:keystore.p12
    key-store-type: PKCS12

I have tried almost all answers in stackoverflow
Some of the answers that I tried are as follows:

This is happening only while running the jar file, I can easily run the spring boot application from IDE (I use Intellij)

  • Changed port from 8181 to 8443(many others also)
  • explicitely specified server port while running jar file (java -jar --server.port=8661)

  • created and tried JKS and PKCS12 files (no luck)

  • I checked whether any other application is running in the port by using netsat -nltp | grep : (no application is listed here) - Checked the same command in root also, doesn't list anything

  • This is only happening while specifying the ssl file, if ssl details are not there in the yaml file, the application easily starts.

Any help is appreciated. Thanks in advance

1 Answers
Related