AroundAround
Sign in Sign up
Menu
  • Home
    • Home
  • Blog
    Technology
    All Technology Software Engineering Web Applications Java Spring Framework Spring Boot AWS
    All Posts
    Smash Posts Transportation Posts Driving Posts Multi Location Post
    Transport
    Driving Articles Driving License Resources Refresh Drive Success Stories Special Articles
    Research
    Popular lists Weblogs Tutorials
    News
    Education Health Sports
    Traffic Signs
    Dubai Traffic Signs Qatar Traffic Signs Abu Dhabi Traffic Signs Saudi Arabia Traffic Signs Kuwait Traffic Signs Kerala Traffic Signs
  • Insights
    Interview Series
    All Interview Series Java Questions Spring Questions Microservices Questions Database Questions
    Lifestyle
    Umrah Articles Dubai UAE visa 180 days calculator Qatar residence visa 180 days calculator Prayer Time Malappuram Sqm to Cent calculator Kerala
    City Explorer
    Sulthan Bathery
  • Mock Tests
    Driving
    Test Home
    Dubai
    RTA Theory Test Parking Knowledge Test Deep-dive Assessment Test
    Abu Dhabi
    RTA Driving Theory Test Deep-dive Assessment Test Saudi Arabia Computer Test
    Other Regions
    Qatar Driving Theory Test Kuwait Driving Theory Test Ajman RTA Theory Test Sharjah RTA Theory Test Bahrain Driving Theory Test Learners License Test - Kerala
    Education
    Kindergarten School
  • Course & Videos
    • CoursesEnroll today
    • Videos20+Watch & Subscribe
  • Questions and Tags
    Topics
    Don't miss Million dollar questions Million Views Day to day life Interview Junky Trendy questions Theory wizard
    Technology
    Java Spring AWS
    Find the differences
    All Find the differences List
    Tags
    macOS AWS Spring
  • About Us
    • Privacy Policy
    • Contact
    • Terms & Conditions
    • Cancellation & Refund Policy
    • Shipping & Delivery Policy
  1. Home
  2. spring-boot
  3. Post

Spring Boot Port Config

Emma Brown
admin
#spring-boot #server
Share post:
Share

Spring Boot on a port *other* than 8080? Tired of port conflicts? Discover the elegant solution to custom TCP/IP port configuration – click to learn more!

How do I change the Spring Boot default port (8080) for TCP/IP?

Solution in a Nutshell

Configuring Spring Boot Application Ports

Spring Boot conveniently defaults to port 8080, but you can easily change it. The primary method is using the server.port property within application.properties (or application.yml).

Using application.properties:

server.port=9090

This sets the port to 9090. Restart your application for the change to take effect.

Using application.yml:

server:
  port: 9090

This achieves the same result using YAML configuration.

Environment Variables:

Alternatively, set the SERVER_PORT environment variable. Spring Boot will automatically pick this up. The exact method depends on your operating system. For example, in Linux/macOS:

export SERVER_PORT=9090

Programmatic Configuration (Advanced):

For more complex scenarios, you can override the port programmatically within your Application class:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;

@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

    //This method configures the port programmatically
    @Bean
    public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> webServerFactoryCustomizer(){
        return factory -> factory.setPort(9090);
    }
}

Remember to choose the method best suited for your needs. For simple port changes, using application.properties or application.yml is recommended. Environment variables offer flexibility for different deployment environments. Programmatic configuration is best for advanced customization. Always restart your application after making any configuration changes.

Sidebar

Search

Tags

#spring-boot #server

Trending posts

Post

HikariCP Shutdown Issue in Spring Boot

Post

Spring Boot REST Client

Post

Date Range Check with Spring Data JPA

Post

Spring Boot Spring Version Upgrade

  • Contact Us
  • Privacy Policy

© Copyright - smashplus 2013-25.