8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE
Asked Answered
P

31

79

I have strange thing when I try to modify Spring project inside my Spring Tool Suite. On the first load (deploy) everything is fine, application compiles and runs on localhost:8080

When I change something inside code and try to redeploy it (Run it again - Run As Spring Boot App) I get error message

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

2016-10-19 00:01:22.615 INFO 10988 --- [ main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3023df74: startup date [Wed Oct 19 00:01:19 CEST 2016]; root of context hierarchy 2016-10-19 00:01:22.616 INFO 10988 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

If I shutdown process on that port manually everything works fine again, but this can't be right way of redeploying Spring app. Am I doing something wrong here?

I'm using :: Spring Boot :: (v1.4.1.RELEASE)

P.S. I'm aware that I can setup some kind of hot-swap mechanism to have automatic reload of page after I change code, but for now I would like to resolve this issue first.

Thanks for any kind of help or info.

Plafker answered 18/10, 2016 at 22:5 Comment(5)
Yes. You need to shutdown the services safely if re-deploying. Then you won't have the service running in the background and creating a port conflict.Retinite
Eclipse (STS) does not support "single instance" Run "configurations" like IntelliJ does. You need to "Terminate" the running one.Pintle
Use this to change port --server.port=8181Reinaldo
check this answer: https://mcmap.net/q/261056/-understanding-the-netstat-outputWoke
In my case, I had apache tomcat installed and running previously. Stopping the tomcat service removed this errorCorkwood
M
114

It sometimes happen even when we stop running processes in IDE with help of Red button , we continue to get same error.

It was resolved with following steps,

  1. Check what processes are running at available ports

netstat -ao |find /i "listening"

We get following

TCP 0.0.0.0:7981 machinename:0 LISTENING 2428 TCP 0.0.0.0:7982 machinename:0 LISTENING 2428 TCP 0.0.0.0:8080 machinename:0 LISTENING 12704 TCP 0.0.0.0:8500 machinename:0 LISTENING 2428

i.e. Port Numbers and what Process Id they are listening to

  1. Stop process running at your port number(In this case it is 8080 & Process Id is 12704)

Taskkill /F /IM 12704 (Note: Mention correct Process Id)

For more information follow these links Link1 and Link2.

Mcdade answered 11/11, 2017 at 6:33 Comment(2)
I found this useful because after closing STS, sometimes the website does not close its local tc server. No amount of clicking red squares helped; additionally, launching from STS and stopping again still did not kill the server sometimes.Arvie
lsof -nP +c 15 | grep LISTEN for macOSErn
E
78

For Mac users(OS X El Capitan):

You need to kill the port that localhost:8080 is running on.
To do this, you need to do two commands in the terminal :N

sudo lsof -i tcp:8080

kill -15 PID 

NB! PID IS A NUMBER PROVIDED BY THE FIRST COMMAND.

The first command gives you the PID for the localhost:8080.
Replace the PID in the second command with the PID that the first command gives you to kill the process running on localhost:8080.

Eran answered 28/3, 2018 at 19:13 Comment(4)
there is no second command. apparently the answer was edited (partially) however, i checked using the history and it worked for me., thanks.Livestock
@FayzaNawaz I have changed it back to the original based on your comment. Thank youEran
This worked for me. How ever I would like to know the meaning of -15 before the PID. And Thanks for posting the solution.Onida
-15 stands for Terminate a process enabling it to end gracefully. Thought it would help for anyone who is curious.Onida
G
29

You have to stop the current process and run your new one. In Eclipse, you can press this button to ReLaunch your application: enter image description here

Gummosis answered 19/2, 2017 at 11:11 Comment(1)
Some of the eclipse doesn't have this option. If unable to find then just try this Window->Preferences, search for Launching. Select the "Terminate and Relaunch while launching" option. and applyDullish
P
27

The reason is one servlet container is already running on port 8080 and you are trying to run another one on port 8080.

    1. Check what processes are running at available ports.

      • For Windows :

      • netstat -ao |find /i "listening" Image01

      OR

      • netstat -ano | find "8080" (Note: 8080 is port fail to start) Image02
    1. Now try to reLaunch or stop your application.

      • To relaunch: you can press this button

    Image03

    • To stop in windows:

    Taskkill /F /IM 6592 Note: Mention correct Process Id

    Image04

    right click on the console and select terminate/disconnect all

    • Go to Task Manager and end Java(tm) platform se binary

    click here to view image

    What is java(tm) platform se binary(Search in google

Another option is :

Go to application.properties file set server.port=0. This will cause Spring Boot to use a random free port every time it starts.

Procurator answered 13/12, 2018 at 14:31 Comment(1)
Thanks, I used "server.port=0", because I got the message "Port already in use" for all ports I wrote even if they are not in use.Tinkle
T
20

Create application.properties file under src/main/resources folder and write content as

server.port=8084

Its runs fine. But every time before run need to stop application first by click on red button upper on the IDE enter image description here

or try

RightClick on console>click terminate/Disconnect All

Trews answered 5/12, 2018 at 9:8 Comment(0)
E
18

In my case, the error occurred as the application was unable to access the keystore for ssl.

Starting the application as root user fixed the issue.

Edina answered 24/2, 2017 at 15:46 Comment(4)
yes and it does shows up in the error logs as well!Kief
Thanks man! I wasted a lot of time because I did not read the whole log! I was going crazy checking if some process was still aliveCompendium
@CarlosCavero With spring boot, I have noticed that we really need to go through the whole log to notice what the issue might be. Generally, there are many reasons why the last error message might show up, and searching online only for the last message does not show satisfactory results :)Edina
Exactly! That's why I upvoted your answer. Looking for other reasons than the typical port busy (even I restarted the pc). Ignore your intuition and do not trust the last message :)Compendium
B
11

If you got any error on your console by saying, “Embedded servlet container failed to start. Port 8080 was already in use.” Then go to application.properties file and add this property “server.port = 8090”.

Actually the default port for spring boot is 8080, if you have something else on that port, the above error will occur. So we are asking spring boot to run on other port by adding “server.port = 8090” in application.properties file.

Boilermaker answered 20/11, 2017 at 13:28 Comment(0)
K
10
  • SOLUTION 1

As a solution ,You can change the default port in application.properties by adding this.

   server.port = 8090

enter image description here

  • SOLUTION 2

If the above solution is not working use this solution. Here we kill the process which used that port using command prompt.

In my case, Port =8090, PID =22208

1). (This use to find PID)

netstat -ano | findstr :8090

2). (Kill that proccess)

 taskkill /PID 22208 /F

enter image description here

Good Luck !

Kopeck answered 8/9, 2021 at 13:13 Comment(0)
L
9

This is a typical startup failure due to the embedded servlet container’s port being in use.

Your embedded tomcat container failed to start because Port 8080 was already in use.

Just Identify and stop the process that's listening on port 8080 or configure (in you application.properties file )this application to listen on another port.

Leveloff answered 18/10, 2016 at 23:41 Comment(1)
Your solution works. I just want to add how we set it to listen on another port. Just put server.port=9000 in your application.propertiesPollination
D
8

There are two ways to resolve this issue.Try option 1 first, if it doesn't work try option 2, and your problem is solved.

1) On the top right corner of your console, there is a red button, to stop the spring boot application which is already running on this port just click on the red button to terminate.

2) If the red button is not activated you need to right click on the console and select terminate/disconnect all. Hope this helps.

Bonus tip:- If you want to run your server on a different port of your choice, create a file named application.properties in resource folder of your maven project and write server.port=3000 to run your application on port 3000

Dyandyana answered 19/3, 2018 at 7:5 Comment(0)
C
6

Am I doing something wrong here?

Yes, you are. One servlet container is already running on port 8080 and you are trying to run another one on port 8080 again.

Either restart the server (If there is button for that in STS) or stop and start it

Colonic answered 18/10, 2016 at 22:10 Comment(1)
true, I actually found Relaunch button inside dashboard. I was expecting Run As to somehow automatically remove previous servlet container from 8080 and run new one, but I guess it doesn't work that way. In any case, there is button inside STS, and it works now.Plafker
S
4

On Linux Machine, save the bash script and execute it. If you want to free port 8080, Input 8080 when prompted

echo "Enter port number to be closed :: "
read port
sudo kill $(sudo lsof -t -i:$port)
Sufferable answered 19/3, 2018 at 9:8 Comment(0)
S
3

Just click red button to stop all services on eclipse than re- run application as Spring Boot Application - This worked for me.

Selfregulated answered 28/10, 2017 at 22:46 Comment(0)
K
3

Open "localhost:8080" on your browser and see what is running on this port. I did it and I just found Oracle 10g XE running on background, so I went to start->Services and stopped all oracle services. Then I redo mvnw spring-boot:run on IntelliJ and it runs like magic.

Keir answered 5/2, 2018 at 20:55 Comment(0)
L
3

If you are using linux system, use the below command.

fuser -k some_port_number/tcp - that will kill that process.

Sample:-

fuser -k 8080/tcp

Second Option: Configure the tomcat to use a new port

Locale answered 21/3, 2019 at 14:53 Comment(0)
A
3

first running from CMD :

netstat -aon |find /i "listening" |find   "8080"

then get PID number and run following command: let it 199,

taskkill /F /PID 199
Adiaphorism answered 13/7, 2021 at 8:22 Comment(0)
B
2

In Spring Boot Application (Using Spring Starter Project) We Have Update Port in Server.xml using Tomcat server and Add this port in application.property( insrc/main/resources) the code is server.port=8085

And update Maven Project then run application

Brayer answered 26/10, 2018 at 13:12 Comment(0)
A
2

There are some processes left in the background on that port, several reasons can cause this problem, but you can solve easily if you end process which is related to 8080 or Spring.

If you are using Linux there is steps how to end process:

  1. Open terminal and type command "htop"
  2. press key F3(it will allow you to search)
  3. Type "8080" if there was no result on 8080 after that try "spring"
  4. Then Press F9(KILL) And press "9"(SIGKILL)

this will kill process which is left on 8080 port and let you run application.

Ascogonium answered 14/12, 2018 at 9:21 Comment(1)
Some might need run sudo apt install htopDetonation
I
2

Print the list of running processes and try to find the one that says spring in it. Once you find the appropriate process ID (PID), stop the given process.

ps aux | grep spring
kill -9 INSERT_PID_HERE

After that, try and run the application again. If you killed the correct process your port should be freed up and you can start the server again.

Ibbison answered 11/4, 2020 at 20:0 Comment(0)
L
2

You can use list open file command and then kill the process like below.

sudo lsof -t -i tcp:8181 | xargs kill -9

or

sudo lsof -i tcp:8181

kill -9 PID
Linnet answered 1/10, 2020 at 13:17 Comment(0)
T
1

No Need to manually start an application every time at time of development to implements changes use 'spring-boot-devtool' maven dependency.

Automatic Restart : To use the module you simply need to add it as a dependency in your Maven POM:

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

When you have the spring-boot-devtools module included, any classpath file changes will automatically trigger an application restart. We do some tricks to try and keep restarts fast, so for many microservice style applications this technique might be good enough.

Trews answered 4/3, 2019 at 6:21 Comment(0)
N
1

Goto Window->Preferences, search for Launching.

Select the "Terminate and Relaunch while launching" option.

Press Apply.

Nur answered 30/7, 2020 at 11:19 Comment(0)
T
1

I was stuck with the similar issue and followed the below steps which resolved my issue.

Please type the following commands in Windows PowerShell. It needs Administrative privileges.

netstat -ano | findstr :8080

TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 5868

TCP [::]:8080 [::]:0 LISTENING 5868

taskkill /PID 5868 /F

SUCCESS: The process with PID 5868 has been terminated.

Turkic answered 3/10, 2023 at 19:7 Comment(0)
F
1

For MacOS

After changing the port number run this command in terminal

lsof -t -i:<PORT_NUMBER> | xargs kill -9
Fichtean answered 1/12, 2023 at 19:51 Comment(0)
B
0

One simple solution for me that worked was to : - Restart the IDE, since the stop Button was no longer visible.

Base answered 2/5, 2020 at 19:56 Comment(1)
If the red button is not activated you need to right click on the console and select terminate/disconnect all.Dyandyana
M
0

One line command for MAC users:

kill `lsof -i -n -P | grep TCP | grep 8080 | tr -s " " "\n" | sed -n 2p`
Mease answered 23/3, 2021 at 0:41 Comment(0)
B
0

If you are facing problem while redeploying, the easiest way would be to not leave port occupied. i.e. close the context of your spring application, so that PORT gets closed alongside.

You can do that in these ways:

//open context.
ConfigurableApplicationContext appContext = SpringApplication.run(Application.class, args);
...
//in the end, close it
appContext.close();

Another way would be, to: open context in try() block

try(ConfigurableApplicationContext appContext =
 SpringApplication.run(Application.class, args))
{
// your code here
}

try() will take care of closing the context, therefore the PORT, even if code breaks somewhere, by calling AutoCloseable.

ref: try-with-resources

Bacitracin answered 12/5, 2021 at 5:10 Comment(0)
C
0

If someone accidentally stumble on this post and his problem is that application is starting two times instead of once and it obviosly fails because port is already in use by first instantion of application. Try add these parameters in yml / properties file.

spring.devtools.restart.quiet-period: 2000

spring.devtools.restart.poll-interval: 3000

https://github.com/spring-projects/spring-boot/issues/25269

https://github.com/spring-projects/spring-boot/issues/12760

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.devtools.globalsettings.configuring-file-system-watcher

Carolann answered 14/12, 2021 at 17:8 Comment(0)
E
0

# If you are on windows os (1st way)

  • open task bar

  • right click on running JDK binary process

  • enter image description here

  • after right click then click on end task

# If you are on windows os (2nd way)

  • pres win+r -> press enter (open windows command permot)
  • enter image description here
  • Taskkill /F /IM <PID>
Elielia answered 6/3, 2022 at 14:30 Comment(0)
Q
0

For Spring Boot 2 and later version add the property to your application configuration file(application.properties or application.yaml):

spring.main.web-application-type=WebApplicationType

The WebApplicationType can be one of:

  • NONE - The application should not run as a web application and should not start an embedded web server.
  • REACTIVE - The application should run as a reactive web application and should start an embedded reactive web server.
  • SERVLET - The application should run as a servlet-based web application and should start an embedded servlet web server.
Quest answered 23/11, 2022 at 10:57 Comment(0)
L
-1

YOU CAN CHANGE THE PORT NUMBER ALSO, TRYING THAT METHOD WILL CHANGE THE ERROR OF PORT 8080

enter image description here

Lansing answered 31/5, 2022 at 2:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.