Spring Boot startup failure because port is already in use

January 04, 2020 No comments Spring Boot QA Failure Startup

1. Spring Boot startup failure

Every Spring Boot exception on start is registered and handled by one of the FailureAnalyzers responsible for wrapping errors and providing human-readable message about what went wrong.

For example when you are trying to run Spring Boot on port that is already in use you should see something similar to the following message (that cames from LoggingFailureAnalysisReporter):

2019-06-09 09:58:19.113 ERROR 10289 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8080 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 8080, or configure this application to listen on another port.

2. Application failed to start - port 8080 already taken

When you see an error like: 'The Tomcat connector configured to listen on port 8080 failed to start', that means another application or service is running on port 8080, and your current instance cannot be started on the same port.

There are a couple of things you can do about this:

  • change port for starting instance,
  • stop other service running on port 8080.

2.1. Changing the starting port for Spring Boot instance

If you don't want to stop the other service running on port 8080, because it is used for different systems, you can change starting port for your Spring Boot by setting server.port parameter in the Spring Boot configuration file.

2.2. Stop service running on port 8080

  • if you have knowledge about the service running on port 8080 simply stop it and run your Spring Boot application,

  • if you don't know what service is blocking your 8080 port try following commands:

On ubuntu use lsof command to find out what is running on a specific port:

sudo lsof -i :8080

The output should look like this:

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 4573 root    4u  IPv6  39218      0t0  TCP *:http-alt (LISTEN)

You can now stop this service by sending -9 signal to this process id (PID) .

sudo kill -9 4573

After unblocking 8080 port, Spring Boot should start without a failure:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::   v2.1.5.RELEASE

2013-07-31 00:08:16.117  INFO 56603 --- [           main] o.s.b.s.app.SampleApplication            : Starting SampleApplication v0.1.0 on mycomputer with PID 56603 (/apps/myapp.jar started by pwebb)
2013-07-31 00:08:16.166  INFO 56603 --- [           main] ationConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6e5a8246: startup date [Wed Jul 31 00:08:16 PDT 2013]; root of context hierarchy
2014-03-04 13:09:54.912  INFO 41370 --- [           main] .t.TomcatServletWebServerFactory : Server initialized with port: 8080
2014-03-04 13:09:56.501  INFO 41370 --- [           main] o.s.b.s.app.SampleApplication            : Started SampleApplication in 2.992 seconds (JVM running for 3.658)
{{ message }}

{{ 'Comments are closed.' | trans }}