How to change server port in spring boot How to change server port in spring boot

Spring boot web application using embedded server by default runs on port 8080. Following are the ways to change default server port from 8080 to say 9090

Follow any of the given five ways to change server port:-

server.port = 9090
2. application.yml
  port: 9090
3. command-line parameter
$ java -jar -Dserver.port=9090 spring-boot-app-1.0.jar


$ java -jar spring-boot-app-1.0.jar --server.port=9090
4. SpringBootApplication main method
public class SpringBootDemoApplication {

    public static void main(String[] args) {

        SpringApplication app = new SpringApplication(SpringBootDemoApplication.class);
        app.setDefaultProperties(Collections.singletonMap("server.port", "9090"));;
5. implement WebServerFactoryCustomizer interface
public class ServerPortCustomizer 
  implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
    public void customize(ConfigurableWebServerFactory factory) {