Spring Boot change Tomcat port command line

The Spring Boot change Tomcat port command line shows you some ways to configure Tomcat port in Spring Boot application. In Spring Boot, the Tomcat default is port 8080. We can change this port with command line, or in the java source code, or update properties file, or update on the IDE such as Eclipse, Intellij, Netbean, etc.

Other interesting posts you may like

Let’s begin:

Update the Properties & Yaml file

Properties file: create your properties file and place it in the classpath directory, for example.

/src/main/resources/application.properties

YAML file: create your yaml file and place it in the classpath directory, for example.

/src/main/resources/application.yml

Update via Java code
We create a component which implements EmbeddedServletContainerCustomizer and this overrides properties and yaml settings.

Using Command Line
Change the Tomcat default port by passing the system properties directly. For example, we have a jar file named spring-boot-change-port-1.0.jar. We run the below command to change port.

Change port in IDE such as Eclipse, Intellij, Netbean

On the Ecipse IDE, you follow the path:
Run -> Run Configurations -> VM arguments
and change port like below

Spring Boot change Tomcat port command line

On the Intelij or Netbeans, you follow the path:
Run -> Edit Configurations -> VM options
and change port like below

Spring Boot change Tomcat port command line

That’s all on the Spring Boot change Tomcat port command line.

References
Spring Boot – Embedded servlet containers


Spring Boot – Externalized Configuration

Leave a Comment

*

Please share it if you found this useful
Hide Buttons