In this tutorials, I am going to show you how to change the Spring Boot Tomcat Port number.

In the previous tutorials I have shown you how to create a simple Spring Boot Hello World application with default port (8080).  You can download the application and make the below changes.

Here I am taking the same example but trying to change the default port number 8080 to 8085.

Spring Boot Tomcat Port  :

In Spring Boot we can change the server port in 3 ways.

  • By updating the file,
  • By configuring the Embedded Servlet Container and
  • By passing the arguments while running the application

Lets see the above 3 scenarios one by one,

Spring Boot gives us a property called [highlight color=”green”]server.port[/highlight] which is used to change the tomcat port from properties file.

To use this, you can update the like below :

Configuring the Embedded Servlet Container :

We can also change the Spring Boot Port number by obtaining the ConfigurableEmbeddedServletContainer object. It allows us to change the runtime server properties like change the serverPort, contextPath, sessionTimeOut and etc.,
package com.onlinetutorialspoint.spring.boot;

import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.stereotype.Component;

public class CustomContainer implements EmbeddedServletContainerCustomizer {
    public void customize(ConfigurableEmbeddedServletContainer container) {

Arguments while running the application :

java -Dserver.port=8585 Application

Based on your requirement, you can use any one among 3 possibilities

Happy Learning 🙂