Start Spring Boot Application on a Different Port Number

This tutorial will teach you how to start your Spring Boot Web application on a different port number.

Read the following tutorial to learn how to start your Spring Boot application on a random port number.

By default, if no port number is configured, our Spring Boot Web application will start on port number 8080. To configure a different port number, you need to update an application.properties file with the following configuration property.

server.port = <port number here>

For example, to make my Spring Boot application startup on port number 8010, I will update the application.properties file in my Spring Boot application with the following configuration property.

server.port = 8010

Set Port Number via Command-line Argument

You can also override the configured port number in your Spring Boot application by setting it via a command-line argument. Below is an example of how you can start up your Spring Boot application and set the server.port number property via a command-line argument.

mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8010

You can also start your Spring Boot application using a java -jar command.

mvn package
java -jar target/<FILENAME.JAR HERE> --server.port=8010

Video Tutorial

I hope this tutorial was helpful to you. I also have many short Spring Boot video tutorials here: Spring Boot and Spring MVC tutorials.

Happy learning!


Leave a Reply

Your email address will not be published. Required fields are marked *