This article contains how to change Spring boot change port using as well as using EmbeddedServletContainerCustomizer

1. Spring Boot change port using

In a standalone application the main HTTP port defaults to 8080, but can be set with server.port (e.g. in or as a System property).


2. Spring Boot change port using  EmbeddedServletContainerCustomizer

package com.javadeveloperzone;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

 * Created by JavaDeveloperZone on 19-07-2017.

// Using a root package also allows the @ComponentScan annotation to be used without needing to specify a basePackage attribute
public class SpringBootConfig {
    public static void main(String[] args) throws Exception {, args);            // it wil start application

    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return (container -> {
            container.setPort(8012);           // your new port


2017-07-20 23:07:38.765 INFO 56804 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8012 (http)
2017-07-20 23:07:38.770 INFO 56804 --- [ main] com.javadeveloperzone.SpringBootConfig : Started SpringBootConfig in 4.03 seconds (JVM running for 4.574)


Spring Boot Change Port Doc

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Tags: ,

Leave a Reply

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