Scrivio Interview library
DebuggingFoundations5 min read · updated 12 November 2026

Startup fails with a message under 'APPLICATION FAILED TO START' saying the port 8080 is already in use, followed by an 'Action' section. What produced this message, and how would you resolve the issue?

That message is produced by a FailureAnalyzer, a Spring Boot component that turns a known startup exception into a description and an action; here it recognised that the embedded server could not bind to port 8080 because another process, often an earlier instance of the same application, already holds it. We resolve it by stopping that process, or by setting server.port to another value, or to 0 for a random port in tests. Without the analyzer we would only see a long stack trace.

Background to this question

Port already in use is probably the first startup failure every Spring Boot developer meets, usually because the application is still running in another terminal or IDE window. It is a good question because the readable message itself is a Spring Boot feature, and because the fix depends on whether we are on a laptop, in a test or on a server. In this answer, we will see what produces the message, find the process that holds the port, look at the ways to change the port, and see what the error looks like without the analyzer.

1What Produced This Message

When Spring Boot's startup fails, SpringApplication catches the exception and passes it to the failure analyzers, a set of FailureAnalyzer classes registered through spring.factories. Each analyzer looks for one type of exception in the cause chain. If one recognises it, it returns a FailureAnalysis with a description and an action, and Boot prints them in the familiar format instead of the raw stack trace.

Text
***************************
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.
Step throughFrom bind failure to readable message
  1. Tomcat binds to port 8080during context refresh
  2. OS refuses: address already in usejava.net.BindException
  3. Boot raises PortInUseExceptionwraps the BindException
  4. Failure analyzers inspect the cause chainone matches the port exception
  5. Print Description and Actioncontext closed, process exits

5 steps in order. Play them, or step through them one at a time.

Here the embedded server, Tomcat by default, tried to bind its connector to port 8080 and the operating system refused because the address was taken. Boot raises a PortInUseException, and the analyzer for that exception produced this text. The full stack trace is still available at debug level, but the analyzer puts the cause and the next step first.

2Finding the Process That Holds the Port

The most common holder is an earlier run of the same application that never stopped, for example started from the IDE and forgotten, or a previous run whose terminal was closed. Another service, such as a different local application or a container, can also use 8080. We find it with a system tool.

Java
# macOS or Linux
lsof -nP -iTCP:8080 -sTCP:LISTEN
# COMMAND PID USER FD TYPE NODE NAME
# java 48213 srini 71u IPv6 TCP *:8080 (LISTEN)
kill 48213 # ask it to stop; Spring Boot shuts down gracefully
# Windows
netstat -ano | findstr :8080
# TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 48213
taskkill /PID 48213

Notice we use a plain kill first, which sends SIGTERM, so the old instance shuts down cleanly. If the holder is a container, docker ps shows which one publishes 8080. Once the port is free, starting again works.

3Changing the Port Instead

Sometimes the other process should keep running, for example when we run two services locally. Then we tell this one to use another port with the server.port property, from any property source.

Java
# application.yml
server:
port: 8081
# or for one run
java -jar orders.jar --server.port=8081
SERVER_PORT=8081 java -jar orders.jar
# random free port
server.port=0 # the server picks a free port; the log shows which one

Port 0 means let the operating system choose a free port. It is ideal for tests, where many contexts might start in parallel, and for running several copies on one machine. On servers we usually want a fixed, known port, set by the deployment.

4Random Ports in Tests

Integration tests that start a real server should never depend on 8080 being free, because a developer may be running the app while the tests run, or the CI agent may run several builds. Spring Boot's test support makes random ports easy and tells us which one was chosen.

Java
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class OrdersApiTest {
@LocalServerPort int port; // e.g. 54231, different each run
@Autowired TestRestTemplate rest; // already points at the random port
@Test void health() {
var r = rest.getForEntity("/actuator/health", String.class);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.OK); // passes
}
}

With RANDOM_PORT, the test never collides with a running application, and the injected client already knows the port, so the test code needs no change.

5What You Would See Without an Analyzer

Without the analyzer, the same failure would appear as a long stack trace: a context refresh failure wrapping a web server exception wrapping a java.net.BindException with the message Address already in use, followed by dozens of lines of framework frames. The cause is in there, but we must read from the bottom up to find it, and newcomers often miss it.

That is the reason Spring Boot ships analyzers for common failures, such as a missing DataSource URL, a bean that cannot be found, or a circular dependency, and the reason teams can write their own for their own exceptions. A good analyzer turns a debugging session into a one-line instruction.

6Follow-up questions

Why is the old instance still holding the port after I stopped it in the IDE?

Sometimes the IDE stops only the launcher, or the process is still in graceful shutdown waiting for requests to finish. lsof shows whether a java process still listens; a plain kill lets it finish shutting down, and kill -9 is the last resort.

Can two Spring Boot apps share port 8080 on one machine?

No, only one process can listen on the same address and port. They need different ports, or different network addresses, for example by binding with server.address, or by running in containers with different published ports.

Where are failure analyzers registered?

In META-INF/spring.factories under the key org.springframework.boot.diagnostics.FailureAnalyzer. Boot's own are there, and our own can be added the same way.

7Conclusion

In this answer, we saw that the APPLICATION FAILED TO START message with its Description and Action comes from a FailureAnalyzer that recognised the port-in-use exception. The usual cause is another process, often an earlier instance of the same app, already listening on 8080. We find and stop it with lsof or netstat, or set server.port to another value, using 0 or RANDOM_PORT in tests, and we saw that without the analyzer only a long stack trace would show the cause.

What to say in the interviewAbout 80 seconds aloud

Open with

That formatted message comes from a FailureAnalyzer. When startup fails, Spring Boot passes the exception to the analyzers registered in spring.factories, and the one for the port-in-use exception recognised that Tomcat could not bind to 8080, so it printed a description and an action instead of the raw stack trace.

Then, if they want more

The cause is that another process is already listening on 8080, and most of the time it is an earlier instance of the same application I left running in the IDE or another terminal.

To fix it, I would find the process with lsof on macOS or Linux, or netstat on Windows, and stop it with a normal kill so it shuts down gracefully. If the other process should keep running, I would change this application's port with server.port, in application.yml, as a command-line argument or as the SERVER_PORT environment variable.

For tests I would use port 0 or webEnvironment RANDOM_PORT with @LocalServerPort, so tests never collide with a running app or with parallel builds. Without the analyzer I would just get a long stack trace ending in a BindException saying address already in use, which is why Boot ships these analyzers and why we can write our own.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Boot reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Startup fails with a message under 'APPLICATION FAILED TO START' saying the port 8080 is...": https://scrivio-interview-library.netlify.app/spring-boot/boot-startup/763f5da472/