如何配置Spring Boot应用程序侦听的TCP/IP端口,使其不使用默认端口8080。


当前回答

在应用程序中。属性文件,添加这一行:

server.port = 65535

该把照片放在哪里?

24.3应用程序属性文件 SpringApplication从应用程序加载属性。属性文件 并将它们添加到Spring环境中: 当前目录下的/config子目录 当前目录 一个类路径/配置包 类路径根 列表按优先级(在位置中定义的属性)排序 列表中较高的位置将覆盖在较低位置定义的那些)。

在我的例子中,我把它放在jar文件所在的目录中。

来自:

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files

其他回答

希望这篇文章能有所帮助

application.properties=> 

server.port=8090

application.yml=> 

server
  port:8090

在应用程序中。资源中的属性文件:

server.port=8082

当你需要一种编程的方式来做它,你可以在启动时设置它:

System.getProperties().put( "server.port", 80 );
SpringApplication.run(App.class, args);

这可能对依赖于环境的端口有帮助。 祝你有愉快的一天

Via

application.properties

服务器。端口= 8082(或任何新的端口号)

via

application.yml

server
  port: 8082

你可以在java代码中设置port:

HashMap<String, Object> props = new HashMap<>();
props.put("server.port", 9999);

new SpringApplicationBuilder()
    .sources(SampleController.class)                
    .properties(props)
    .run(args);

或者在application.yml中:

server:
    port: 9999

或者在application.properties中:

server.port=9999

或者作为命令行参数:

-Dserver.port=9999