How to configure port for a Spring Boot application

前端 未结 30 1236
名媛妹妹
名媛妹妹 2020-11-22 13:36

How do I configure the TCP/IP port listened on by a Spring Boot application, so it does not use the default port of 8080.

30条回答
  •  北海茫月
    2020-11-22 14:03

    1.1 Update via a properties file.

    /src/main/resources/application.properties

    server.port=8888

    Update via a yaml file.

       server:
    
         port: 8888
    

    EmbeddedServletContainerCustomizer

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

提交回复
热议问题