Fix "Web server failed to start. Port 8080 was already in use" in Spring Boot
*************************** 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.
- org.springframework.boot.web.server.PortInUseException: Port 8080 is already in use
- Web server failed to start. Port 8081 was already in use.
- Caused by: java.net.BindException: Address already in use
- Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.PortInUseException: Port 8080 is already in use
Another program is already listening on port 8080, often a previous instance of your application still running in the IDE. Find it with lsof -i :8080 (macOS / Linux) or netstat -ano | findstr :8080 (Windows) and stop it, or change the port with server.port=8081.
What this error means
At startup, Spring Boot launches an embedded web server (Tomcat by default, or Jetty, Undertow, Netty) that must open the configured port, 8080 by default. The operating system only lets one process listen on a given port and address: if the port is already taken, opening it fails with a BindException, which Spring Boot turns into a PortInUseException and then into this "APPLICATION FAILED TO START" report. Your code is not at fault: you need to free the port or pick another one.
Common causes
- Previous instance still running: you restarted the application in IntelliJ, Eclipse or VS Code without stopping the first one, or a
mvn spring-boot:runis running in another terminal. - Another service on port 8080: an installed Tomcat, Jenkins, a Docker container published on 8080 or another dev server.
- Two Spring Boot applications (microservices) both keeping the default port.
- Zombie process: the IDE crashed or was closed abruptly and the JVM stayed in the background.
Step-by-step fix
-
Find the process (macOS / Linux)
lsofshows the name and PID of the program listening. If it is one of yourjavaprocesses, stop it; for a system service, stop it properly rather than killing it.lsof -nP -iTCP:8080 -sTCP:LISTEN kill 12345 # PID from the previous command # still running after a few seconds? kill -9 12345 -
Find the process (Windows)
The last column of
netstatis the PID;tasklistgives its name. You can also use PowerShell withGet-NetTCPConnection.netstat -ano | findstr :8080 tasklist /FI "PID eq 12345" taskkill /PID 12345 /F # PowerShell Get-Process -Id (Get-NetTCPConnection -LocalPort 8080 -State Listen).OwningProcess -
Stop the old instance in the IDE
In IntelliJ IDEA, open the Run or Services window and stop every Spring Boot configuration (red square button). Enable "Allow multiple instances" only if you also change the port of each instance.
-
Or change the application port
Set
server.portinsrc/main/resources/application.properties(orapplication.yml).server.port=0picks a random free port, handy for tests.# application.properties server.port=8081 -
Change the port without touching the code
Pass the port as an argument or an environment variable, useful locally or in production (Docker, PaaS that impose a port).
java -jar app.jar --server.port=8081 SERVER_PORT=8081 java -jar app.jar ./mvnw spring-boot:run -Dspring-boot.run.arguments=--server.port=8081 ./gradlew bootRun --args='--server.port=8081' -
Docker case
If a container already publishes 8080,
docker psshows it in the PORTS column. Stop it or publish your application on another host port (-p 8081:8080).docker ps --filter "publish=8080" docker stop <container>
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Give each microservice its own fixed port in its configuration (
server.port=8081,8082…). - Stop the application before relaunching it, or use Spring Boot DevTools, which restarts inside the same JVM instead of launching a new one.
- In integration tests, use
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)so they never conflict.
Frequently asked questions
lsof shows nothing but the port is still taken, why?
The process may belong to another user or to root: run sudo lsof -nP -iTCP:8080 -sTCP:LISTEN. On Windows, open the terminal as administrator.
How do I disable the web server completely?
For a batch or console application without HTTP, set spring.main.web-application-type=none: no port is opened.
Port 8080 taken on Windows by a system service, what can I do?
Some ports are reserved by Hyper-V or WSL. netsh interface ipv4 show excludedportrange protocol=tcp lists the reserved ranges: pick a port outside them with server.port.
Useful tools for this error
More Java, Kotlin & .NET errors
- Fix "java.lang.NullPointerException: Cannot invoke … because … is null" in Java
- Fix "UnsupportedClassVersionError: compiled by a more recent version of the Java Runtime"
- Fix "Could not resolve all files for configuration" and "Could not find" in Gradle
- Fix "Failed to configure a DataSource: 'url' attribute is not specified" in Spring Boot
- Fix "java.lang.OutOfMemoryError: Java heap space" (and GC overhead limit exceeded)
- Fix "Object reference not set to an instance of an object" (NullReferenceException) in C#
- Fix "lateinit property binding has not been initialized" in Kotlin (Android)