Solved: Intellij Spring boot Gradle Error — Web server failed to start. Port 8080 was already in use.
Have you ever encountered the below error in a Spring boot Gradle app on your WINDOWS machine with IntelliJ IDEA?
WEB SERVER FAILED TO START PORT **** WAS ALREADY IN USE
There could be a couple of solutions that you can try.
Solution 1: Find and Kill the process consuming the port
-
Find a process consuming the port
Use the below command in the WINDOWS command prompt using ADMINISTRATOR or WINDOWS PowerShell using ADMINISTRATOR
netstat -a -n -p tcp -o | findstr 49415
The result of the above command could be eitherNO RECORDS
orTCP 192.168.1.32:49415 52.226.139.180:443 ESTABLISHED 7536
Note down the Process ID — last digits7536
in our case. -
Kill the process
In order to kill the process using the below command
kill --pid--
that iskill 7536
Solution 2: Check the JDK version
If the Java SDK version is not your application supports then you can get such an error.
-
Find the Java SDK version of the project in IntelliJ IDEA
In order to find the Java SDK version set for the project in IntelliJ IDEA editor, on a Windows machine
- Click File
- Click on Project Structure
- On the left panel, under Project Settings, Click on the Project menu
- Find the option of SDK set for the current project.
- Edit the Java SDK for the project in IntelliJ IDEA
Once you find the SDK option as per the above steps, Select OR edit the SDK version of lower OR higher, and click OK.
Depending on the project you may need to set the SDK to the latest version or older version. Setting SDK to 1.8 should work in the most cases
Port Already in Use Spring Boot — Fixed
📘 Premium Read: Access my best content on
Medium member-only articles
— deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed.
Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount):
Explore My Udemy Courses
— Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers):
Java Guides on YouTube
In Spring Boot applications, if you see an error indicating that a port is already in use, it means another process (possibly another instance of your application or a different application) is already running and using the desired port. Here’s a typical error message:
***************************
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.
The default port for a Spring Boot web application is 8080.
How to Resolve the «Port Already in Use» Error
Change the Spring Boot Application Port
You can change the port your Spring Boot application runs on by adding or modifying the server.port property in the application.properties or application.yml file:
server.port=8081
Or, if you’re using YAML format:
server:
port: 8081
Specify the Port Using Command Line
When running your Spring Boot application, you can specify the port directly using a command line argument:
java -jar your-app.jar --server.port=8081
Identify the Process Using the Port
You can identify the process using a specific port with various tools based on your operating system.
For Linux/macOS:
lsof -i :8080
For Windows:
netstat -ano | findstr 8080
Once identified, you can decide whether to kill the process or let it run.
Kill the Process
If you decide to kill the process of occupying the port.
For Linux/macOS:
kill -9 <PID>
Where <PID> is the process ID.
For Windows:
taskkill /F /PID <PID>
This will free up the port, allowing you to start your Spring Boot application on it.
Ensure You’re Not Starting the Application Multiple Times
If you’re developing in an IDE, ensure you don’t have multiple instances of your application running. This is a common oversight where developers might accidentally run the application more than once.
Use Random Port During Development
If you’re not particular about the port and just want to run the application during development, you can configure Spring Boot to use a random port:
server.port=0
This will pick an available port from the system’s available range.
Remember, the root cause of the «port already in use» error is always another process that’s already bound to the specified port. Whether you decide to change your application’s port or stop the conflicting process depends on your specific needs and environment.
Related Spring Boot and Microservices Tutorials/Guides:
The Hidden Magic of Spring Boot: Secrets Every Developer Should Know
What Happens When You Hit a Spring Boot REST API Endpoint (Behind the Scenes)
Spring Boot Exception Handling
Build CRUD REST API with Spring Boot, Spring Data JPA, Hibernate, and MySQL
Spring Boot DELETE REST API: @DeleteMapping Annotation
Spring Boot PUT REST API — @PutMapping Annotation
Spring Boot POST REST API
Spring Boot GET REST API — @GetMapping Annotation
Spring Boot REST API with Request Param | Spring Boot Course
Spring Boot REST API with Path Variable — @PathVariable
Chapter 13: Understanding @SpringBootApplication Annotation | Spring Boot Course
Chapter 5: Create Spring Boot Project and Build Hello World REST API | Spring Boot Course
10 Real-World Spring Boot Architecture Tips Every Developer Should Follow
Top 10 Spring Boot Tricks Every Java Developer Should Know
Debugging Spring Dependency Injection Issues — Very Important
Common Code Smells in Spring Applications — How to Fix Them
Spring Boot + OpenAI ChatGPT API Integration Tutorial
Spring Boot Course -> New Series on Medium ❤️
Spring Boot Microservices with RabbitMQ Example
React JS + Spring Boot Microservices
Dockerizing a Spring Boot Application
How to Change the Default Port in Spring Boot
How to Change Context Path in Spring Boot
Top 10 Spring Boot REST API Mistakes and How to Avoid Them (2025 Update)
Spring Boot REST API Best Practices
Spring Boot Security Database Authentication Example Tutorial
Spring Boot Security Form-Based Authentication
Spring Boot Security In-Memory Authentication
What is Spring Boot Really All About?
Why Spring Boot over Spring?
Top 10 Spring Boot Key Features That You Should Know
Spring vs Spring Boot
Setting Up the Development Environment for Spring Boot
Spring Boot Auto-Configuration: A Quick Guide
Spring Boot Starters
Quick Guide to Spring Boot Parent Starter
Spring Boot Embedded Servers
Spring Boot Thymeleaf Hello World Example
Chapter 10: Spring Boot DevTools | Spring Boot Course
Chapter 13: Spring Boot REST API That Returns JSON | Spring Boot Course
Spring Boot REST API That Returns List of Java Objects in JSON Format
Top 10 Spring Boot Mistakes and How to Avoid Them
Advanced Spring Boot Concepts that Every Java Developer Should Know
What Are Microservices in Spring Boot?
Integrating React Frontend with Spring Boot ChatGPT API (Step-by-Step Guide)
Build a Chatbot Using Spring Boot, React JS, and ChatGPT API
Top 10 Mistakes in Spring Boot Microservices and How to Avoid Them (With Examples)
Spring Boot Security Best Practices: Protecting Your Application from Attacks
🔄 Dependency Injection in Spring (Explained with Coding Examples)
⚙️ How Spring Container Works Behind the Scenes
How Spring Container Works Behind the Scenes (Spring Container Secrets Revealed!)
Spring @Component vs @Bean vs @Service vs @Repository Explained
How Component Scanning Works Behind the Scenes in Spring
How Spring Autowiring Works Internally
Top 20 Spring Boot Best Practices for Java Developers
Build Spring Boot React Full Stack Project — Todo App [2025 Update]
Spring vs Spring MVC vs Spring Boot
Spring Boot Best Practices: Use DTOs Instead of Entities in API Responses
Spring Boot DTO Tutorial (Using Java record) – Complete CRUD REST API Implementation
Spring Boot Architecture: Controller, Service, Repository, Database and Architecture Flow
Java Stream filter() Method with Real-World Examples
Spring Boot Auto Configuration Explained | How It Works
Spring Boot Profiles: How to Manage Environment-Based Configurations
Create a Custom Spring Boot Starter | Step-by-Step Guide
Spring Boot Starter Modules Explained | Auto-Configuration Guide
Deploy Spring Boot Applications with Profile-Based Settings | Step-by-Step Guide
Spring Boot Performance Tuning: 10 Best Practices for High Performance
Spring Boot @ComponentScan Annotation | Customizing Component Scanning
Difference Between @RestController and @RequestMapping in Spring Boot
Spring Boot @Cacheable Annotation – Improve Performance with Caching
Spring Boot Redis Cache — @Cacheable Complete Guide
When to Use @Service, @Repository, @Controller, and @Component Annotations in Spring Boot
Why, When, and How to Use @Bean Annotation in Spring Boot App
Java Spring Boot vs. Go (Golang) for Backend Development in 2025
Is Autowired Annotation Deprecated in Spring Boot? Everything You Need to Know
🚫 Stop Making These Common Mistakes in Spring Boot Projects
Top 10 Mind-Blowing Spring Boot Tricks for Beginners
Why Choose Spring Boot Over Spring Framework? | Key Differences and Benefits
How to Run a Spring Boot Application | 5 Easy Ways for Developers
What is AutoConfiguration in Spring Boot? | Explained with Example
Customize Default Configuration in Spring Boot | 5 Proven Ways
Chapter 12: Understanding SpringApplication.run() Method Internals | Spring Boot Course
What is CommandLineRunner in Spring Boot?
How to Create Custom Bean Validation in Spring Boot
Can You Build a Non-Web Application with Spring Boot?
How to Disable Auto-Configuration in Spring Boot (Step-by-Step Guide)
Top 25 Spring Boot Interview Questions and Answers for Beginners
How to Use Java Records with Spring Boot
Spring Boot Constructor Injection Explained with Step-by-Step Example
🚫 Stop Using @Transactional Everywhere: Understand When You Actually Need It
🚫 Stop Writing Fat Controllers: Follow the Controller-Service-Repository Pattern
🚫 Stop Using Field Injection in Spring Boot: Use Constructor Injection
🚫 Stop Sharing Databases Between Microservices: Use Database Per Service Pattern
10 Java Microservices Best Practices Every Developer Should Follow
How to Choose the Right Java Microservices Communication Style (Sync vs Async)
How to Implement Event-Driven Communication in Java Microservices (Step-by-Step Guide with Kafka)
Stop Building Tight-Coupled Microservices: Aim for Loose Coupling
Spring Boot Microservices E-Commerce Project: Step-by-Step Guide
Spring Boot Microservices with RabbitMQ Example
React JS + Spring Boot Microservices
The Ultimate Microservices Roadmap for Beginners: Building Modern Scalable Systems
What Are Microservices in Spring Boot?
Top 5 Message Brokers Every Developer Should Know
Top 10 Spring Cloud Microservices Best Practices [Removed Deprecated Features]
Best Tools for Microservices Development in 2025
How to Break a Monolithic Application into Microservices (E-Commerce Use Case)
Monoliths Aren’t Dead — Microservices Are Just Overused
When to Break a Monolith: A Developer’s Checklist
👑 Java Is Still the King of Microservices — And Here’s the Proof
5 Microservices Design Patterns You Must Know in 2025
Bulkhead Pattern in Microservices — Improve Resilience and Fault Isolation
Strangler Fig Pattern in Microservices — Migrate Monolith to Microservices
Event Sourcing Pattern in Microservices (With Real-World Example)
Circuit Breaker Pattern in Microservices using Spring Boot 3, WebClient and Resilience4j
CQRS Pattern in Microservices
Aggregator Design Pattern in Microservices — A Complete Guide
Database Per Service Pattern in Microservices
API Gateway Pattern in Microservices — A Complete Guide
Saga Pattern in Microservices: A Step-by-Step Guide
Microservices Are a Mess Without These Java Design Patterns️
Java Microservices Interview Questions and Answers for Freshers
Top Microservices Interview Questions and Answers for Experienced Professionals
Top 10 Microservices Design Pattern Interview Questions and Answers
Top Microservices Tricky Interview Questions You Should Know (With Answers)
Microservices Best Practices: Building Scalable and Resilient Systems
Why Microservices Are the Future of Software Architecture
Microservices with Spring Cloud: Simplify Your Architecture
Spring Boot and Microservices Roadmap for Beginners [2025 Update]
Best Programming Language for Microservices Project Development in 2025
My 50+ Must-Read Microservices Tutorials, Articles and Guides on the Medium Platform
Table of Contents
If you’re trying to start a web server and see the error:
“Web server failed to start. Port 8080 was already in use.”
You’re not alone. This is a common problem when a port your app needs—often 8080
for development—is already being used by another process. Here’s what’s happening and how to fix it on Windows and macOS.
🔍 What Does This Error Mean?
Ports are like doors that apps use to communicate over the network. If another program already takes port 8080, your server can’t use it and crashes with that error.
Common culprits:
- Another instance of your app is already running
- A browser-sync tool or frontend server
- Docker, Jenkins, Tomcat, or other dev tools
Step 1: Find the Process Using Port 8080
Open Command Prompt and run:
netstat -ano | findstr :8080
This shows you the PID (Process ID) using port 8080.
Example output:
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 12345
Here, 12345
is the PID.
Step 2: Kill the Process
Now run:
taskkill /PID 12345 /F
Replace 12345
with the PID from the previous command. The /F
flag forces the process to terminate.
🛠 How to Fix It on macOS
Step 1: Find the Process Using Port 8080
Open Terminal and run:
lsof -i :8080
This lists processes using port 8080.
Example:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 6789 john 22u IPv6 0x... 0t0 TCP *:http-alt (LISTEN)
Here, 6789
is the PID.
Step 2: Kill the Process
Run:
kill -9 6789
The -9
flag forcefully stops the process.
Alternative Solutions and Best Practices
- Change your server’s port
- Spring Boot: set
server.port
inapplication.properties
/application.yml
, or pass--server.port=9090
on the command line. - Node.js: modify the port constant in your startup script, e.g.
app.listen(process.env.PORT || 3000)
.
- Spring Boot: set
- Graceful shutdown hooks
Implement shutdown hooks in your application so it unbinds cleanly—especially important for Java apps (e.g. using a@PreDestroy
method orRuntime.getRuntime().addShutdownHook(...)
). - Port-checking scripts
Add a lightweight preflight check in your build or startup scripts to detect free ports and either notify you or automatically pick an available port. - Docker port mappings
If you’re running in containers, ensure yourdocker run -p
ordocker-compose.yml
mappings don’t collide with the host ports you need. - Continuous monitoring
Use basic monitoring tools (e.g.,fd://
or simple cron jobs) to alert you when port conflicts arise in staging or production.
✅ After That…
Try restarting your server. If it starts successfully, you’re good.
To avoid the issue in the future:
- Make sure to shut down local servers when you’re done
- Consider changing the port (e.g., to 3000, 5000) if 8080 is often in use
Gopi is an Engineering Manager with over 14 years of extensive expertise in Java-based applications. He resides in Europe and specializes in designing and scaling high-performance applications.
Gopi Gorantala Newsletter
Join the newsletter to receive the latest updates in your inbox.
Your email address
Please check your inbox and click the link to confirm your subscription.
Please enter a valid email address!
An error occurred, please try again later.
Comments
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
How many times during our development we got this error after pushing the start button?
***************************
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.
Process finished with exit code 0
Sometimes our IDE fail to close the task in the OS and it cannot find anymore what’s running on our computer.
How to find and destroy the task
On MacOS and Linux, from the console/terminal you can
lsof -i tcp:8080
lsof will show the LiSt of Open Files on the open socket (-i) tcp:8080 (for unix systems almost everything is a file).
You will get an answer similar to:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 18902 marco 252u IPv6 0xe56dd35caa2d493 0t0 TCP *:us-srv (LISTEN)
at this point you can simply kill 18902
(18902 is the PID found previously).
Find the process in Windows
In Windows you dont have lsof
you can use netstat
.
netstat -ano | findstr :8080
-ano that can be easily remembered if you know a bit of italian … means:
- a: Displays all active TCP connections and the TCP and UDP ports on which the computer is listening.
- n: Displays active TCP connections, addresses and port numbers are expressed numerically.
- o: Displays active TCP connections and includes the process ID (PID).
You will receive an answer similar to:
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 1234
You can use the Resource Monitor to kill the Process 1234