How to Change Tomcat Port in Spring Boot

In this post, I am going to share two easy ways to change the tomcat port in Spring Boot projects. Basically, I am going to answer how to change the default port in the spring boot tomcat server.

Change Spring Boot Tomcat Port
Change Spring Boot Tomcat Port

1. By Editing Properties or Yaml file

application.properties

Edit properties file if you are using maven as your build tool located at: /src/main/resources/application.properties and specify the port at which you want to run your project as shown below.

server.port=8888

In the sample shown above, the Spring Boot Tomcat will run using port 8888 instead of default 8080.

application.yml

Similarly, if you are using Gradle as your build tool, you will have to edit .yaml located at /src/main/resources/application.yml as shown below.

server:
  port: 8888

In the sample shown above, the Spring Boot Tomcat will run using port 8888 instead of default 8080.

2. Using Command Line

Update the port bypassing the system properties directly when you are running the jar file you generated after building your Spring Boot Project.

java -jar -Dserver.port=8888 spring-boot-example-1.0.jar

In the sample shown above, the Spring Boot Tomcat will run using port 8888 instead of default 8080.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *