如何为Spring Boot应用程序配置端口

本文翻译自:How to configure port for a Spring Boot application

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


#1楼

参考:https://stackoom.com/question/1QSh8/如何为Spring-Boot应用程序配置端口


#2楼

As said in docs either set server.port as system property using command line option to jvm -Dserver.port=8090 or add application.properties in /src/main/resources/ with 文档中所述,可以使用jvm -Dserver.port=8090命令行选项将server.port设置为系统属性,或者在/src/main/resources/添加application.properties

server.port=8090

For random port use 对于随机端口使用

server.port=0

#3楼

You can specify port by overriding EmbeddedServletContainerFactory bean within your configuration (java based or xml). 您可以通过覆盖配置(基于Java或xml)中的EmbeddedServletContainerFactory bean来指定端口。 There you can specify port for used embedded servlet container. 您可以在此处为使用的嵌入式Servlet容器指定端口。 Please, see Spring Boot - Core "Embedded Servlet Container Support" paragraph and example there. 请参阅Spring Boot-Core “嵌入式Servlet容器支持”段落和示例。 Hope this helps. 希望这可以帮助。


#4楼

In case you are using application.yml add the Following lines to it 如果您使用的是application.yml ,请在其中添加以下几行

server:
     port: 9000

and of course 0 for random port. 对于随机端口,当然是0。


#5楼

There are two main ways to change the port in the Embedded Tomcat in a Spring Boot Application. 在Spring Boot应用程序中,有两种主要方法可以更改嵌入式Tomcat中的端口。

Modify application.properties 修改application.properties

First you can try the application.properties file in the /resources folder: 首先,您可以尝试/ resources文件夹中的application.properties文件:

server.port = 8090

application.properties文件

Modify a VM option 修改虚拟机选项

The second way, if you want to avoid modifying any files and checking in something that you only need on your local, you can use a vm arg: 第二种方法,如果要避免修改任何文件并检入只需要在本地上执行的操作,则可以使用vm arg:

Go to Run -> Edit Configurations -> VM options 转到运行->编辑配置-> VM选项

-Dserver.port=8090

使用vm arg更改端口

Additionally, if you need more information you can view the following blog post here: Changing the port on a Spring Boot Application 另外,如果您需要更多信息,则可以在此处查看以下博客文章: 更改Spring Boot应用程序上的端口


#6楼

  1. As everyone said, you can specify in application.properties 大家都说过,您可以在application.properties中指定
    server.port = 9000 (could be any other value) server.port = 9000 (可以是任何其他值)

  2. If you are using spring actuator in your project, by default it points to 如果您在项目中使用弹簧执行器,则默认情况下它指向
    8080, and if you want to change it, then in application.properties mention 8080,如果要更改它,则在application.properties中提及
    management.port = 9001 (could be any other value) management.port = 9001 (可以是任何其他值)

发布了0 篇原创文章 · 获赞 75 · 访问量 56万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105466179