Java

Change Spring Boot server port


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!

bgasparotto

Recent Posts

Python function decorator

This guide will show you how to create a Python function decorator with a few…

2 years ago

Got permission denied while trying to connect to the Docker daemon socket

This guide will show you how to fix the error Got permission denied while trying…

2 years ago

Python virtual environment on Intellij IDEA

This guide will show you how to create a Python virtual environment on Intellij IDEA…

2 years ago

Find and kill processes on Linux and Mac by port number

This tutorial will quickly show you how to to find and kill processes on Linux,…

2 years ago

Python: Relocation R_X86_64_PC32 against symbol can not be used when making a shared object Error

This guide shows a possible solution for Python error Relocation R_X86_64_PC32 against symbol can not…

2 years ago

Kubernetes useful commands

I condensed below a cheat sheet of Kubernetes useful commands. I will keep updating this…

2 years ago