How to Change Port for Spring Boot Applications
Spring Boot is a popular framework used to develop Java-based web applications. By default, Spring Boot applications run on port 8080. However, in some cases, you may need to change the port number for your application. In this article, we’ll explore how to change the port for Spring Boot applications.
Step 1: Open the application.properties File
To change the port for your Spring Boot application, you’ll need to modify the application.properties file. This file is located in the src/main/resources directory of your Spring Boot project.
Step 2: Set the Server Port
Once you’ve opened the application.properties file, you can set the server port by adding the following line:
server.port=XXXX
Replace “XXXX” with the desired port number. For example, if you want to run your application on port 8081, the line should look like this:
server.port=8081
Step 3: Save the File and Run the Application
After setting the server port in the application.properties file, save the file and run your Spring Boot application. Your application will now run on the new port that you’ve specified.
Bonus Tip: Setting the Port via Command-Line Arguments
You can also set the server port via command-line arguments when running your Spring Boot application. To do this, simply add the following argument when starting your application:
--server.port=XXXX
Replace “XXXX” with the desired port number.
Conclusion
Changing the port for a Spring Boot application is a straightforward process. By modifying the application.properties file or using command-line arguments, you can quickly change the port number to suit your needs. Remember to choose a port that is not already in use by another application on your system.
If you found this article helpful, please share it with your friends and colleagues. Thank you for reading!