By default, all applications that you create using Spring Boot will run on Port 8080, if you want your application to run on some other port, you need to add server.port property in the application.properties file located in the resources folder.
1. Change default 8080 Port using configuration file
- Go to src > main > resources package in your project,
- If you have a application.properties file,
server.port=<custom_port_no>
- If you have application.yml file,
server:
port: <custom_port_no> - Save the file.
- Run your Spring Boot app and it should now run on the custom port you set.
![Change Spring Boot Default 8080 Port Example Change Spring Boot Default 8080 Port Example](https://code2care.org/java/ways-to-change-default-8080-port-spring-boot/images/Change Spring Boot Default 8080 Port Example.jpg)
2. Change default 8080 Port using VM Argument in IDE
You can also change the default port using the VM Argument, add it to your IDE,
IntelliJ IDE- Go to Menu: Run,
- Select Edit Configurations.
- Now in VM options add -Dserver.port=<custom_port_number>
Visual Studo Code IDE:
- Open launch.json file under .vscode directory
- Add the below "vmArgs": "-Dserver.port=<custom_port_number>"
![Add Custom Port VS Code Spring Boot App Add Custom Port VS Code Spring Boot App](https://code2care.org/java/ways-to-change-default-8080-port-spring-boot/images/Add Custom Port VS Code Spring Boot App.jpg)
Eclipse IDE
- Right Click on your Project,
- Select Run Configurations,
- Add "-Dserver.port=<custom_port_number>" under VM Arguments
3. Change default 8080 Port while running the jar file:
When you are executing your jar file app, you can pass the option --server.port
Example:
% java -jar my/jar/path/my-boot-app.jar --server.port=8070
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
- Where is Cron Crontab jobs log file Located in Ubuntu Linux - Ubuntu
- [fix] Java NullPointerException ComparableTimSort countRunAndMakeAscending when sorting a List - Java
- How to Send Email using Java - Java
- How to remove quotes from a String in Python - Python
- How to know Roblox Version Details on Mac - MacOS
- How to change Chrome Spell Check from UK English to US English - Chrome
- How to Toggle Light/Dark Mode in Google Colab - Google
- Get HTML table td, tr or th inner content value with id or name attribute - Html