DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Auto Logging in Class and Method Level Using Custom Annotations in Spring Boot App
  • Spring Boot Pet Clinic App: A Performance Study
  • Improving Backend Performance Part 1/3: Lazy Loading in Vaadin Apps
  • Advanced Kubernetes Setup for Spring Boot App With PostgreSQL DB

Trending

  • Teradata Performance and Skew Prevention Tips
  • A Guide to Container Runtimes
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Contextual AI Integration for Agile Product Teams
  1. DZone
  2. Coding
  3. Frameworks
  4. Changing the Default Port of Spring Boot Apps [Snippets]

Changing the Default Port of Spring Boot Apps [Snippets]

Let's take a look at three different approaches you can take to defining your Spring Boot app's default Tomcat port, as well as the impacts of those approaches.

By 
Hussein Terek user avatar
Hussein Terek
·
Mar. 19, 18 · Code Snippet
Likes (14)
Comment
Save
Tweet
Share
186.4K Views

Join the DZone community and get the full member experience.

Join For Free

By default, Spring Boot applications run on an embedded Tomcat via port 8080. In order to change the default port, you just need to modify the server.port attribute, which is automatically read at runtime by Spring Boot applications.

In this tutorial, we provide a few common ways of modifying the server.port attribute.

application.properties

Create an application.properties file under src/main/resources and define the server.port attribute inside it:

server.port=9090


EmbeddedServletContainerCustomizer

You can customize the properties of the default servlet container by implementing the EmbeddedServletContainerCustomizer interface as follows:

package com.programmer.gate;

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

public class CustomContainer implements EmbeddedServletContainerCustomizer {
    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        container.setPort(9090);
    }
}


The port defined inside the CustomContainer always overrides the value defined inside application.properties.

Command Line

The third way is to set the port explicitly when starting up the application through the command line. You can do this in two different ways:

  • java -Dserver.port=9090 -jar executable.jar
  • java -jar executable.jar –server.port=9090

The port defined using this way overrides any other ports defined through other ways.

Spring Framework Spring Boot app

Published at DZone with permission of Hussein Terek, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Auto Logging in Class and Method Level Using Custom Annotations in Spring Boot App
  • Spring Boot Pet Clinic App: A Performance Study
  • Improving Backend Performance Part 1/3: Lazy Loading in Vaadin Apps
  • Advanced Kubernetes Setup for Spring Boot App With PostgreSQL DB

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!