How to Fix “Port 8080 Already in Use” in Spring Boot (Mac, Linux, Windows)
When running a Spring Boot application, you may see the following error:
APPLICATION FAILED TO START – Port 8080 was already in use
This happens when another process is already listening on the same port.
Below are the quickest ways to find and stop that process on Mac, Linux, and Windows.
***************************
APPLICATION FAILED TO START
***************************
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.
Process finished with exit code 0
What causes this error?
- Another Spring Boot app still running
- Docker container using the port
- Node / Java app not shut down correctly
- IDE crash left the process alive
Find the process using port 8080
On macOS and Linux, from the terminal you can run:
lsof -i tcp:8080
On Unix-like systems, everything is treated as a file, so we search for the process by inspecting open files.
lsof will show the LiSt of Open Files on the open socket (-i) tcp:8080 .
You will get an answer similar to:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 18902 marco 252u IPv6 0xe56dd35caa2d493 0t0 TCP *:us-srv (LISTEN)
If the command returns nothing, try running it with sudo. Sometimes the process is running with higher privileges than your current shell.
At this point, you can stop the process with:
kill 18902
If the process does not stop, you can force it:
kill -9 18902
⚠️ Use this only as a last resort, as it does not allow the process to shut down gracefully.
Find the process in Windows
On Windows, you don’t have lsof, so you can use netstat instead.
netstat -ano | findstr :8080
-ano that can be easily remembered if you know a bit of italian ... means:
- a: Displays all active TCP connections and the TCP and UDP ports on which the computer is listening.
- n: Displays active TCP connections, addresses and port numbers are expressed numerically.
- o: Displays active TCP connections and includes the process ID (PID).
You will receive an answer similar to:
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 1234
You can use the Resource Monitor to kill the process with PID 1234 or use the command line:
taskkill /PID 1234 /F
Quick alternative: change the port (optional)
If you don't want to take the risk to kill the process that somebody else (suspiciously) is running on your machine you can start the application on a different port.
In application.properties:
server.port=8081
Stop a process from Java (optional)
If your application starts external processes using Java APIs, you can stop them programmatically:
process.destroy(); // graceful shutdown
process.destroyForcibly(); // force shutdown
Prevent this issue in the future
- Stop apps from IDE before rerunning
- Use different ports per service
- Check running containers
- Use spring.application.name + logging
CheatSheet
| OS | Find PID | Kill the process |
|---|---|---|
| macOS / Linux | lsof -i :8080 | kill -9 |
| Windows | netstat -ano | findstr :8080 | taskkill /F /PID |