Skip to content
  1. LuzineDebug
  2. Java, Kotlin & .NET
  3. ***************************
Java, Kotlin & .NET Beginner ≈ 5 min to fix

Fix "Web server failed to start. Port 8080 was already in use" in Spring Boot

Error message
***************************
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
In short

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.

Be the first to confirm this fix

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

  1. Previous instance still running: you restarted the application in IntelliJ, Eclipse or VS Code without stopping the first one, or a mvn spring-boot:run is running in another terminal.
  2. Another service on port 8080: an installed Tomcat, Jenkins, a Docker container published on 8080 or another dev server.
  3. Two Spring Boot applications (microservices) both keeping the default port.
  4. Zombie process: the IDE crashed or was closed abruptly and the JVM stayed in the background.

Step-by-step fix

  1. Find the process (macOS / Linux)

    lsof shows the name and PID of the program listening. If it is one of your java processes, stop it; for a system service, stop it properly rather than killing it.

    bash
    lsof -nP -iTCP:8080 -sTCP:LISTEN
    kill 12345        # PID from the previous command
    # still running after a few seconds?
    kill -9 12345
  2. Find the process (Windows)

    The last column of netstat is the PID; tasklist gives its name. You can also use PowerShell with Get-NetTCPConnection.

    powershell
    netstat -ano | findstr :8080
    tasklist /FI "PID eq 12345"
    taskkill /PID 12345 /F
    
    # PowerShell
    Get-Process -Id (Get-NetTCPConnection -LocalPort 8080 -State Listen).OwningProcess
  3. 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.

  4. Or change the application port

    Set server.port in src/main/resources/application.properties (or application.yml). server.port=0 picks a random free port, handy for tests.

    ini
    # application.properties
    server.port=8081
  5. 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).

    bash
    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'
  6. Docker case

    If a container already publishes 8080, docker ps shows it in the PORTS column. Stop it or publish your application on another host port (-p 8081:8080).

    bash
    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

All Java, Kotlin & .NET errors →