Patrick
Patrick

Reputation: 637

Spring Boot: The Tomcat connector configured to listen on port 8080 failed to start

I was running a Spring Boot program and at first everything went fine. But after I hit ctrl + c and stopped the program, I restart the program and met the following error:

***************************
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.

My program is a jar file, so I start it with java -jar myJar, and stop it by ctrl + c.

At first I thought this was because port 8080 was used. But when I tried the following commands I found there was nothing running on port 8080,

lsof -i:8080 # shows nothing
sudo lsof -i tcp:8000 # shows nothing

So I think there's no process running on port 8080 but why spring gives me that error?

I've tried another port 8081 and met the same problem again. But when I use server.port=0, it works. Can anyone give some suggestions on what to do? Thanks so much!!

Upvotes: 1

Views: 9155

Answers (3)

Indra Uprade
Indra Uprade

Reputation: 808

I experience the similar issue when i was using ServerSocketIO. Problem in my code was, where Thread.sleep was used just after server.start(). So in ideal case if you just inject the ServerSocketIO bean and invoke the start method on it, Tomcat server will server the incoming request. handling of socket shutdown needs to be handled gracefully though in case of application crash or something...

Upvotes: 0

Ammar Ali
Ammar Ali

Reputation: 690

It happens when you press ctrl+c when tomcat is running. This will turn the port to waiting. Firstly freeing up state by using this command: fuser 8080 -k then run the program again.

Upvotes: 0

clevertension
clevertension

Reputation: 7077

I meet with similar issue when the web server visit is busy, so your server socket may have TIME_WAIT state, in this case the tomcat-embeded-server in spring boot can't bind this port because SO_REUSEADDR is not set to true enter image description here

so my solution is to use Jetty in spring boot, you can change your pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

Upvotes: 1

Related Questions