How to configure port for a Spring Boot application

前端 未结 30 1602
名媛妹妹
名媛妹妹 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:27

    You can set port in java code:

    HashMap props = new HashMap<>();
    props.put("server.port", 9999);
    
    new SpringApplicationBuilder()
        .sources(SampleController.class)                
        .properties(props)
        .run(args);
    

    Or in application.yml:

    server:
        port: 9999
    

    Or in application.properties:

    server.port=9999
    

    Or as a command line parameter:

    -Dserver.port=9999
    

提交回复
热议问题