Spring Boot 简明教程

Spring Boot - Tomcat Port Number

Spring Boot 允许您在不同的端口号上多次运行同一应用程序。本章将对此进行详细说明。请注意,默认端口号为 8080。

Spring Boot lets you to run the same application more than once on a different port number. In this chapter, you will learn about this in detail. Note that the default port number 8080.

Custom Port

application.properties 文件中,我们可以为 server.port 属性设置自定义端口号

In the application.properties file, we can set custom port number for the property server.port

server.port = 9090

application.yml 文件中,您可以找到以下内容:−

In the application.yml file, you can find as follows −

server:
   port: 9090

Random Port

application.properties 文件中,我们可以为 server.port 属性设置随机端口号

In the application.properties file, we can set random port number for the property server.port

server.port = 0

application.yml 文件中,您可以找到以下内容:−

In the application.yml file, you can find as follows −

server:
   port: 0

Note − 如果在启动 Spring Boot 应用程序时 server.port 号码为 0,则 Tomcat 将使用随机端口号。

Note − If the server.port number is 0 while starting the Spring Boot application, Tomcat uses the random port number.