Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ‚̧ ūüíĽ
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

Spring Boot 2 - change default application port from source code

0 contributions
6 points

To change change default application port from source code with Spring Boot 2 it is necessary to create own bean that overrides default port configuration. This article shows how to do it.


  • read this article to see different methods how to change default port with Spring Boot,
  • read this article to see the exact place where to keep bean¬†configurations.

Spring Boot 2.x.x - web server factory bean

In this approach webServerFactory() method that returns ConfigurableServletWebServerFactory object is used. file:

package com.dirask.examples;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class ServerConfig {

    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

        factory.addConnectorCustomizers(connector -> {

        return factory;
} file location:

Server port with file location - Spring Boot 2.x.x + IntelliJ
Server port with file location - Spring Boot 2.x.x + IntelliJ


0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey ūüĎč
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more