HTML Tutorial: How to Fix “Web Server Failed to Start Port 8080 Was Already in Use” Error in Spring Boot
If you are a Spring Boot developer, you might have encountered the error message “Web Server Failed to Start Port 8080 Was Already in Use.” This error occurs when the port 8080, which is the default port for Spring Boot applications, is already being used by another process on your computer. In this tutorial, we will explore different methods to fix this issue.
Method 1: Identify and Kill the Process
The first step in resolving this issue is to identify the process that is using port 8080 and terminate it. Here’s how you can do it:
- Step 1: Open Command Prompt or Terminal on your computer.
- Step 2: Run the following command to find the process ID (PID) using port 8080:
netstat -ano | findstr :8080
You will see an output similar to this:
TCP 127.0.1:8080 0.0:0 LISTENING PID
Note down the PID associated with port 8080.
- Step 3: Now, run the following command to terminate the process using the identified PID:
taskkill /F /PID PID
Replace “PID” with the actual process ID you obtained in step 2.
Once you have terminated the conflicting process, try running your Spring Boot application again. If everything goes well, the error should be resolved.
Method 2: Change the Default Port in Spring Boot
If you frequently encounter port conflict issues, you can change the default port for your Spring Boot application. Here’s how:
- Step 1: Open your Spring Boot project in your preferred Integrated Development Environment (IDE).
- Step 2: Locate the application.properties or application.yml file in your project’s resources directory.
- Step 3: Open the file and add the following line to specify a new port:
server.port=8081
Replace “8081” with any available port number of your choice.
Save the file and run your Spring Boot application. It should now start on the new port you specified.
Method 3: Kill Processes Using Port 8080 Automatically
If you want a more automated approach, you can use tools like NMap, Fuser, or PIDof. These tools allow you to find and kill processes using a specific port. Here’s an example using NMap:
- Step 1: Install NMap on your computer if you haven’t already.
- Step 2: Open Command Prompt or Terminal.
- Step 3: Run the following command to find and kill processes using port 8080:
nmap -p 8080 -sV | grep "Open"
You will see a list of processes using port 8080. Note down the process name or PID.
- Step 4: Now, run the following command to terminate the processes using the identified process name or PID:
killall PROCESS_NAME
Replace “PROCESS_NAME” with the actual process name you obtained in step 3.
Using tools like NMap, Fuser, or PIDof can be convenient if you frequently encounter port conflicts and want a quicker way to identify and kill processes using a specific port.
Conclusion
Resolving the “Web Server Failed to Start Port 8080 Was Already in Use” error is crucial for running Spring Boot applications smoothly. By following the methods mentioned in this tutorial, you can easily fix this issue and continue developing your Spring Boot projects without any interruptions.
Remember to always check for conflicting processes using port 8080 and terminate them, change the default port in your Spring Boot application if needed, or use automated tools like NMap to identify and kill processes. With these solutions at hand, you can ensure a hassle-free development experience with Spring Boot.