Last Updated on 20/08/2022
This tutorial will show you three different ways to change Spring Boot server port from its default 8080 to any other port you like.
The following steps are agnostic to your current Spring Boot’s embedded server, it should not make any difference whether you are using Tomcat, Jetty or Undertow.
Change server port through application.properties
In your application.properties
file, add the server.port
property to change Spring Boot server port. The following configuration sets the port to 9000
:
server.port=9000
Change server port through maven startup
However, if you’d like to change it upon startup without modifying the source code, launch the application through maven passing the server.port
as an argument. You should run the command below from the root directory of your project (the one containing the pom.xml
file:
mvn spring-boot:run -Drun.arguments="--server.port=9000"
Change server port on jar startup
Additionally, if you already have your application packaged into a jar file, launch it passing the server.port
parameter:
java -jar -Dserver.port=9000 springboot-helloworld-0.0.1-SNAPSHOT.jar
Hope it helps.
Cya!