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.
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>"
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
- Disable Control Scroll Zoom-in and Zoom-out in Notepad++ - NotepadPlusPlus
- Background task activation is spurious error - Windows 10, Office 2016, Office 365 - HowTos
- Fix: ModuleNotFoundError: No module named azure-core - Azure
- What is HTTP 500 Internal Server Error Code on web browsers - HowTos
- How to install curl on Alpine Linux - Linux
- Add X days from today in Command Line - HowTos
- Fix: >>> pip install - SyntaxError: invalid syntax - PIP
- Java TLSv1.3 protocol code example using SSLSocket - Java