The Spring Boot error “Web server failed to start. Port 8080 was already in use.” arises when port 8080 is already assigned to another application or has not been released. In this scenario, the Spring Boot application attempts to configure port 8080 to start a web server, but since the port is unavailable, the error occurs. The recommended action is to identify and stop the process that is currently listening on port 8080 or configure the Spring Boot application to use a different port.

The Spring Boot application uses Tomcat as its web server, and the default port for Tomcat is 8080. If another application is already utilizing port 8080, attempting to start the Spring Boot application will result in an exception. This occurs because Tomcat cannot use port 8080 if it’s already in use by another application. To resolve this issue, you need to either stop the process using port 8080 or configure the Spring Boot application to use a different port that is available.



Exception

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.


Root Cause

When Tomcat is already running on port 8080, and a Spring Boot application attempts to use Tomcat as its default web server on the same port, an issue arises. This occurs because port 8080 is already in use, either by a different application or the current application is already running, and you are attempting to start it again. To resolve this, ensure that the current application is stopped or choose a different port for the Spring Boot application to avoid conflicts.



Solution 1

If you’ve already started and are running a Spring Boot application, attempting to run it again can lead to port conflicts. To resolve this, stop all instances of the application, including those running in terminals, command lines, or services.

Additionally, restart your Integrated Development Environment (IDE) to ensure a fresh start. Verify that no other applications are currently using port 8080 to prevent conflicts. By taking these steps, you can avoid port-related issues when restarting your Spring Boot application.



Solution 2

If external applications are already using port 8080, you can identify and stop them to free up the port for your Spring Boot application. In the task manager or system monitor, check for running applications that may be listening on port 8080. Identify the processes using commands or tools that display active ports and associated processes.

For Linux, you can use the following command to find the application using port 8080:

ps -ef | grep 8080

kill -9 <process id>

This command lists the processes using port 8080. Once you identify the process, you can stop it by killing the process. After stopping the conflicting application, you can run your Spring Boot application without port conflicts.



Solution 3

If there are valid applications already running on the default port (e.g., 8080) and stopping them is not feasible, an alternative solution is to change the default listening port in the application.properties file of your Spring Boot application. By modifying the port configuration, you can avoid conflicts with existing applications.

Here’s an example of how you can change the port in application.properties:

application.properties

server.port=80

How to create simple Spring Boot Application with Main method



Leave a Reply