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.
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.
@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.
SERVER_PORT=0 ./gradlew bootRunHow 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.