Skip to content
Latchkey

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

The embedded server (Tomcat/Netty/Jetty) tried to bind port 8080 and the OS reported it already bound. In CI this is usually a leftover process or two tests that both start a full server on the fixed port.

What this error means

Startup fails with "Web server failed to start. Port 8080 was already in use." Its Action block suggests changing the port or freeing it.

Spring Boot
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.

Common causes

Two tests start a full server on the fixed port

Multiple @SpringBootTest(webEnvironment = DEFINED_PORT) or parallel jobs bind the same 8080, and the second fails.

A prior process did not release the port

A background app from an earlier step is still listening, so the new startup cannot bind.

How to fix it

Use a random port in tests

Let Spring pick a free port so no two tests collide and no fixed port is required.

src/test/java
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ApiIntegrationTest {
  @LocalServerPort int port;
}

Set server.port explicitly for bootRun in CI

If you must run a real server, pick a known-free port for the CI step.

Terminal
SERVER_PORT=0 ./gradlew bootRun

How to prevent it

  • Use RANDOM_PORT for integration tests instead of a fixed 8080.
  • Stop any background app before starting another on the same port.
  • Avoid DEFINED_PORT unless the port is genuinely reserved.

Frequently asked questions

What causes ""Port 8080 was already in use""?
Multiple @SpringBootTest(webEnvironment = DEFINED_PORT) or parallel jobs bind the same 8080, and the second fails.
How do I fix "Port 8080 was already in use"?
Let Spring pick a free port so no two tests collide and no fixed port is required.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card