Address localhost 8080 is already in use как исправить

Solution

You can use the troubleshooting tips below.

Troubleshooting Tip #1

  1. Exit Eclipse

  2. Open a web browser and visit, http://localhost:8080

  3. If you see a “Tomcat” web page then that means Tomcat is running as a Windows service. To stop Tomcat running as a Windows services, open your Windows Control Panel. Find the service “Apache Tomcat” and stop it.

  4. If you don’t see a “Tomcat” web page, then stop the appropriate process displayed.


Troubleshooting Tip #2 – GUI Option

Steps to free port which is already used to run Tomcat server in Eclipse

  1. On MS Windows, select Start > All Programs > Accessories > System Tools >Resource Monitor

  2. Expand the Network Tab

  3. Move to the section for Listening Ports

  4. Look in the Port column and scroll to find entry for port 8080

  5. Select the given process and delete/kill the process

  6. Return back to Eclipse and start the Tomcat Server, it should start up now.


Troubleshooting Tip #3 – Command-Line Option

Steps to free port which is already used to run Tomcat server in Eclipse

For example , suppose 8080 port is used , we need to make free 8080 to run tomcat

Step 1: (open the CMD command)

C:Usersusername>netstat -o -n -a | findstr 0.0:8080

TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 3116

Now , we can see that LISTENING port is 3116 for 8080 ,

We need to kill 3116 now

Step 2:

C:Usersusername>taskkill /F /PID 3116

Step 3: Return back to Eclipse and start the Tomcat Server, it should start up now.

====

Mac/Linux SOLUTION

Step 0: Exit Eclipse

Step 1: Open a terminal window

Step 2: Enter the following command to find the process id

lsof -i :8080
This will give output of the application that is running on port 8080

Step 3: Enter the following command to kill the process

kill $(lsof -t -i :8080)

Step 4: Return back to Eclipse and start the Tomcat Server, it should start up now.

In this post, We will try to understand the Web server failed to start Port 8080 was already in use error and how to fix it.

Web server failed to start. Port 8080 was already in use

In the network, an IP address identifies each machine. Similarly, The network port identifies the application or process running on a machine. When an application wants to use a port, the OS binds one. However, when multiple applications want to use the same port, there is a port clash.

In our case, port 8080 was already being used by another application and hence the web server failed to start. Usually, you would get this error in the case of ports 8080, 8081, 9090, etc. So in general, If you get a “port 8080 was already in use” error, then it is certain that another application is already using that port.

This is most likely due to bad configuration from your end, running the application multiple times, or not using proper startup and shutdown scripts.

Fix for Web server failed to start

As we know, The cause is that another process is running on the same port. To solve this, you have two options.

  1. Try to run the application on a port other than 8080.
  2. Identify and stop the process running on that specific port

Option 1: Run your web server on a different port

Most of the application frameworks provide options to change the ports they listen to. For instance, you can change the application port of a spring boot application in the following ways.

You can provide a server.port configuration with a different port number in the application.properties file.

server.port=9090Code language: Properties (properties)

You can also pass the port number as an application parameter.

java - jar my-server.jar --server.port=9090Code language: Bash (bash)

Or a JVM parameter.

java - jar -Dserver.port=9090 my-server.jarCode language: Bash (bash)

This way, The application starts on a different port. Thus the “Web server failed to start. Port 8080 was already in use” error is avoided.

There is a detailed post on how to change the default tomcat port number in 5 different ways. You can also find more details on how the spring boot configuration works in their official documentation.

Option 2: Kill the server running on port 8080

Sometimes, the other process is just an old instance of the same application or an application that you don’t want to run. In these cases, it is best to identify and kill them so that you can start your application on that specific port. To do that you need to first identify the process. Second, you need to kill it.

Say you got the error for running on port 8080. Then you should use the below command for identifying the process or service.

Finding and killing process running on port 8080 on Linux/Mac

One of the following commands should give the process ID (PID) of the application or service running on port 8080.

sudo lsof -n -i :8080 | grep LISTEN
sudo netstat -nlp | grep :8080
sudo ss -lptn 'sport = :8080'Code language: Bash (bash)
fix for Web server failed to start. Port 8080 was already in use
python http server running on port 8080 with PID 25321

With the PID from the above output, you can kill the process using the following commands.

#to kill process gracefully
kill -15 25321Code language: Bash (bash)

or

#To force kill a process
kill -9 25321Code language: Bash (bash)

By killing the process occupying the port on 8080, the web server can start without any problems.

For your use, replace the process id with the process id that you found on your machine.

Finding and killing process running on port 8080 on windows

Similarly, You can run the following command to identify a process running on a port in windows.

netstat -ona | findstr :8080 | findstr LISTENINGCode language: Bash (bash)
command to find process running on port 8080 in windows
process 23928 listening on port 8080

Once you get hold of the process id, you can use the following command to kill it.

taskkill /PID 25321 /F Code language: Bash (bash)

As I said earlier, for your machine, the process ID may be different. The /F is there to force kill the process. In most cases, you will not require this flag.

Conclusion

So we learned ports work and how to solve “Port 8080 was already in use” errors on application startup. If you liked this article, then you might like to read about the following titles.

on April 9, 2018 •

Problem Statement 

Have you bumped into this error before when trying to start the Tomcat server? 

java.net.BindException: Address already in use – Tomcat Error

Caused by: org.apache.catalina.LifecycleException: service.getName(): “Tomcat”;  Protocol handler start failed

Caused by: java.net.BindException: Address already in use

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

Tomcat Error

Resolution 

The error message states that you have another process which is already serving the port 8080, and as a result your application server is not able to bind to that specific port.

Needless to say, only 1 process can be bound to a given port at any point of time. You will bump into this error, if you are starting tomcat when the earlier instance of tomcat is already running and attached to 8080 port.

To resolve this issue, you have 2 options —

Kill the previous instance

Find the process number that is listening at the given port —

$ lsof -i TCP:8080

COMMAND PID USER   FD   TYPE      DEVICE                    SIZE/OFF  NODE    NAME
java              9270 Samir 39u IPv6   0x737a9d99c9a999a9 0t0           TCP *:http-alt (LISTEN)

Kill the process running at the given port — 

$ kill 9270

Run the application on a different port

You can modify the port number on which your application is running in the application.yml file —

server:
port: ${service.port:8092}

Do let me know in comments below if this did not resolve your issue, and I will be happy to assist.


Categories: Java

The Springboot project reports an error when port 8080 is occupied

8080

Solution:

method one:

Configuration file modification port

server.port=8081

 Method Two:

Under dos, close the process occupying port 8080 (It is best to run dos as an administrator

  1. View port 8080, display the process occupying the port
 netstat   -ano|findstr  8080 

  1. Run the taskkill command that comes with windows, which will occupy the process number of the port, and /f force the end.
taskkill  /pid  5048 /f 

Start and run Springboot again, and the problem is solved.

The spring boot Web server failed to start. Port 8080 was already in use. error occurs because port 8080 is already configured with another application, or port 8080 has not been released yet. The spring boot application is trying to configure port 8080 to start a web server. Since the port can not be used, this error is thrown. The action is Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port.

The Spring boot application uses tomcat as a web server. The default tomcat port is 8080. If any application listens to port 8080 and if you start the spring boot application, this exception is thrown as tomcat can not use port 8080.

Exception

Description:
 Web server failed to start. Port 8080 was already in use.
 Action:
 Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

Root Cause

Tomcat is running on port 8080. Spring boot application uses tomcat as the default web server. The port 8080 is currently being used by the application and tomcat is trying to listen to port 8080. A different application may be used for port 8080. Or the current application is already running. You ‘re trying to get started again.

Solution 1

You’ve already started and running the spring boot application. Now you’re trying to run the spring boot application again. Stop all the instance or restart your IDE.

You may be running an instance on a terminal or command line, or run as a service. Now you’re trying to get your IDE started again. Check all the applications that can use port 8080 and make sure the application is not started.

Solution 2

Some external applications already use port 8080. Check the running application in the task manager, stop the application that listen to port 8080.

The running application can be identified by the process commands. Identify the process that uses port 8080. Stop the application so that port 8080 is released to the other application to be used. Run the command below in linux to find the application that uses port 8080, and then kill the process if you want to stop it.

ps -ef | grep 8080

kill -9 <process id>

Solution 3

Some of the valid applications are running the default port. The application that may be used for other purposes can not be stopped. The other option is to change the default listening port in the application.properties and start the spring boot application again.

application.properties

server.port=80

How to create simple Spring Boot Application with Main method

Добавить комментарий