Change the default port in Spring Boot

Vevek Pandian
Techsmart
Published in
3 min readJul 18, 2021

--

Hope you would have enjoyed and tried out building the Spring Boot application using my first blog on Booting Spring Boot for beginners. It helps beginners to kickstart creating a simple REST application using Spring Boot. If you have added the starter spring-boot-starter-web in your dependencies, Spring Boot by default has embedded Tomcat running in port 8080. But in many cases, one has to change the default configuration for our specific needs. This tutorial will talk about various ways to change the default port of the embedded server in Spring Boot.

The Apache Tomcat® software is an open-source implementation of the Jakarta Servlet, Jakarta Server Pages, Jakarta Expression Language, Jakarta WebSocket, Jakarta Annotations, and Jakarta Authentication specifications. These specifications are part of the Jakarta EE platform.

Property files

The easiest and straightforward way of changing the default port of the embedded server in Spring Boot is property files. Navigate to src/main/resources and create a file application.yml and add the following code.

We have changed the default port to 8081. Build and run the application and you can see the port has changed to 8081.

--

--