others-How to run spring boot application with specified port in command line?

1. Purpose

In this post , I would demonstrate how to specify the port when running a spring boot application.

2. The solution

2.1 The configuration of port in normal way

In normal, we configure the port of spring boot applications in such way:


  port: 8080



But this is not elastic when we run spring boot application multiple times, they are on the same port, we can only start one instance in one host

mvn spring-boot:run

2.2 The solution

We can run spring boot application in following way to specify the port number of spring boot applications:

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

Or , if you have packaged spring boot to jar, then we can specify port in command line as follows:

java -jar xxx.JAR --server.port=8008

3. Summary

In this post, I demonstrated how to specify port number when running spring boot applications . That’s it, thanks for your reading.