43
votes

I'm developing a REST API using Spring Framework.

First I wasn't able to run my application because of the same problem. The port 8080 on my computer is busy. Then I found out that one alternative to solve this problem is creating an application.properties file under src/main/resources folder. That's what I made, and set up the server to listen on port 8090. This worked but only for the first time, now I'm getting the same exception whenever I try to run the application for the second time.

Description:

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

As far as I know, this framework makes use of an embedded instance of apache tomcat to deploy every application.

My guess is, the server is not getting restarted the second time I try to run the app, that's why the output says " The port may already be in use or the connector may be misconfigured"

So, a more specific question would be, how can I manage the embedded instance of apache tomcat either manually or programmatically?

I've also modified the port in the application.properties file twice. It works fine, but again, only for the first time. As you can imagine I cannot do the same each time the app is going to be executed.

18
Are you stopping the application before you try to start it the second time? If so, how are you doing that? It sounds like the first instance of the application is still running.Andy Wilkinson
No, I'm not. I actually thought the framework would perform this operations behind the scenes.Sandoval0992
For a temporary workaround, you can set the port to server.port=0 which will find a random open port to use. Although I suggest you find out a way to stop your application properly.codingbash
It's working fine applying the solution you gave me. Thank you for finding the time to ask this question.Sandoval0992
Hi @codingbash, Lyk yu mentioned, i made my port number as 0 in the properties file. Still, I'm getting the same error. "The Tomcat connector configured to listen on port 0 failed to start. The port may already be in use or the connector may be misconfigured. " any guess on my issue??Bandham Manikanta

18 Answers

94
votes
  1. Find the process ID (PID) for the port (e.g.: 8080)

    On Windows:

    netstat -ao | find "8080"
    

    Other Platforms other than windows :

    lsof -i:8080
    
  2. Kill the process ID you found (e.g.: 20712)

    On Windows:

    Taskkill /PID  20712 /F
    

    Other Platforms other than windows :

    kill -9 20712   or kill 20712
    
41
votes

On the console, looking at the topmost right side of the dialog you should see a red button kinda like a buzzer. To stop the spring boot application properly you just ran, go ahead and hit this particular "red" button and your problem is solved. Hope this helps!

25
votes

Another easy way of solving this error is right clicking in the console and click on Terminate/Disconnect All. Afterwards run the application it should work fine.

13
votes

Issue: It's because either you are not stopping your application or the application is already somehow running on the same port somehow.

Solution, Before starting it another time, the earlier application needs to be killed and the port needs to be freed up.

Depending on your platform you can run the below commands to stop the application,

on windows

netstat -anp | find "your application port number"` --> find PID

taskkill /F /PID

on Linux,

netstat -ntpl | grep "your application port number"

kill pid // pid you will get from previous command

on Mac OS

lsof -n -iTCP:"port number"

kill pid //pid you will get from previous command

12
votes

Find the process and terminate it. On Windows do a Control+Alt+Delete and then find the "Java(TM) Platform SE Binary" process under the Processes Tab. For example: enter image description here

On Ubuntu, you can use "ps aux | grep java" to find the process and "kill -9 PID_NUMBER" to kill the process.

OR

If you're using a Spring boot application, go to application.properties and add this:

server.port = 8081
5
votes

In case your app is run on httpS, make sure you put right values under the following properties:

server.ssl.key-store-password=
server.ssl.key-alias=

I got the same error when I put the wrong values here

4
votes

this issue can be resolved using 2 ways:

  1. Kill application running on 8080
netstat -ao | find "8080"

Taskkill /PID 1342 /F
  1. change spring server port in application.properties file

server.port=8081

3
votes

On Windows:

To get started, open the command prompt by clicking on Start and then typing cmd. In the command window, go ahead and type in the following command:

netstat -a -n -o

In the command above, the -o parameter is what will add the PID to the end of the table. Press enter and you should see something like this:

enter image description here

Now to see the name of the process that is using that port, go to Task Manager by pressing CTRL + SHIFT + ESC and then click on the Process tab. In Windows 10, you should click on the Details tab.

By default, the task manager does not display the process ID, so you have to click on View and then Select Columns.

You might also need to look into services running in background. To do that right-click and select open services as shown below:

enter image description here

Hope it helps :)

2
votes
  1. check the port which is busy: netstat -ntlp
  2. kill that port : kill -9 xxxx
2
votes

The easier way to solve this is changing the port on the application.properties file;

enter image description here

server.port=8081

1
votes

There are two options to handle/avoid this situation.

  1. Before re-running the application just terminate the previous connection.
  • Open the console --> right click --> terminate all.
  1. If you forgot to perform action mention on step 1 then
  • Figure out the port used by your application, you could see it the stack trace in the console window
  • Figure out the process id associated to port by executing netstat -aon command in cmd
  • Kill that process and re-run the application.
0
votes

if it's convenient for you, and you don't want to use the command line, you can reboot your computer, it helps!

0
votes

For those who are experiencing same problem after controlling there is no suspicious java process which allocate the port, there is no red square on eclipse to terminate any process and also there is no change even you try different port for your spring boot application.

might sound stupid but; restarting eclipse works. :)

0
votes

In your windows os follow the following steps:


1)search services 2)Find Apache tomcat 3)Right-click on it and select end 4)Run your spring boot application again it will work

0
votes

We have had the same issue in eclipse or intellij. After trying many alternative solutions, I found simple solution - add this config to your application.properties: spring.main.web-application-type=none

0
votes

If you have devtools like auto build dependency remove it. It is automatically build your project and run it. When you build manually it show port in use.

0
votes

If none of the solutions above worked and you are using IntelliJ Idea (I'm using version 2020.3) you can go on your services tab and try to right click on your running configuration then click on clear content.

running server

-1
votes

right click on console and stop

right click on your console and terminate. or click on stop

enter image description here