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

The embedded web server (Tomcat, Jetty or Undertow) tried to bind to the port and the operating system refused because something else is already listening there. Spring Boot wraps the underlying java.net.BindException: Address already in use in a PortInUseException, and the failure analyzer prints the message above.

The full trace from a Tomcat-based app looks like this:

org.springframework.boot.web.server.PortInUseException: Port 8080 is already in use
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229)
	at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:984)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:610)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
	at com.example.demo.DemoApplication.main(DemoApplication.java:10)
Caused by: java.net.BindException: Address already in use
	at java.base/sun.nio.ch.Net.bind0(Native Method)
	at java.base/sun.nio.ch.Net.bind(Net.java:555)
	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:233)

Exact line numbers differ between versions. What matters is the Caused by: java.net.BindException at the bottom: it confirms the cause is the port, not your beans.

TLDR

  • Message names a port and the app just restarted: a previous run of the same app is still alive. Find it with lsof -i :8080 (Linux/macOS) or netstat -ano | findstr :8080 (Windows) and stop it.
  • Message names a port you never configured, such as 8081 or 9090: check management.server.port and other servers your app starts.
  • Message says 8080 after you set another port: your override is not applied. Check the profile, command-line arguments and the SERVER_PORT environment variable.
  • Running several instances on purpose: use server.port=0 or give each instance its own port.
lsof -i :8080

An earlier run of the same app is still alive

This is the usual cause. The IDE run configuration was stopped with the detach button, a terminal running mvn spring-boot:run was closed without ending the Java process, or the app was started in the background and forgotten. You recognize it because the error appears right after a restart and the port was free before you first started the app.

Find the process:

# Linux / macOS
lsof -i :8080
ss -ltnp | grep 8080
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java    48213 dev   112u  IPv6 981234      0t0  TCP *:8080 (LISTEN)
# Windows (cmd)
netstat -ano | findstr :8080
tasklist /FI "PID eq 48213"

If the command column says java, check that it is your app before killing it, for example with jps -l, which prints the main class for each PID. Then stop it:

kill 48213          # Linux / macOS, add -9 only if it does not exit
taskkill /PID 48213 /F   # Windows

Another program owns the port

Port 8080 is a common default for Jenkins, other Tomcat installs, proxies and Docker containers. If lsof shows something that is not Java, or a Docker proxy process, the port is taken by that program. Either stop it or move your app:

# src/main/resources/application.properties
server.port=8081

The same setting works as a command-line argument or environment variable, which is useful in CI and containers:

java -jar app.jar --server.port=8081
SERVER_PORT=8081 java -jar app.jar

A container published with -p 8080:8080 holds the host port even when nothing inside it is related to your app. docker ps shows which containers publish it.

The message names a port you never set

If the failing port is not 8080, look for a second server. When management.server.port is set, Actuator runs on a separate port and that server can fail on its own:

server.port=8080
management.server.port=8081

Here a clash on 8081 prints “Port 8081 was already in use” even though your main port is fine. The same applies to apps that open extra connectors, gRPC servers or embedded brokers. Read the port number in the message before assuming it is the main one.

Your server.port override is not being applied

Spring Boot resolves properties from several sources, and the order matters: command-line arguments beat environment variables, which beat application.properties. So an old SERVER_PORT exported in your shell or set in the IDE run configuration silently wins over the file. To see which value was used, check the startup log line:

Tomcat initialized with port 8080 (http)

Older Boot versions print Tomcat initialized with port(s): 8080 (http). If the number is not what you set, look for the property in an inactive profile file (application-dev.properties is only read when the dev profile is active, see Spring profiles not loading), a .env file loaded by your IDE, or a SPRING_APPLICATION_JSON variable.

Running several instances or tests on one machine

Two copies of the app on one host cannot share a port. For tests, @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) avoids the conflict and the port can be injected with @LocalServerPort:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class DemoApplicationTests {

    @LocalServerPort
    int port;

    @Test
    void contextLoads() {
        System.out.println("Running on " + port);
    }
}

For local runs, server.port=0 makes the OS pick a free port, and the chosen value appears in the log line Tomcat started on port 54321 (http). Tests using the default MOCK environment do not start a server at all, so a port clash in tests means something requested a real one.

Reading the trace when it is buried in startup output

When the error appears in a long startup log, the useful part is the last Caused by: block and the port number in the first line, not the lifecycle and refresh frames in between. Pasting the whole output into the Debugly stack trace formatter collapses the Spring framework frames and puts the BindException and your own main frame next to each other. If startup fails on a different exception instead, see BeanCreationException troubleshooting for how to read chained causes.