如何为 Spring Boot 应用程序配置端口
问题描述:
如何配置 Spring Boot 应用程序侦听的 TCP/IP 端口,使其不使用默认端口 8080.
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.
答
As 在文档中说 要么使用 jvm 的命令行选项将 server.port
设置为系统属性 -Dserver.port=8090
或在 /src/main/resources/
中添加 application.properties
和
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
server.port=8090
随机端口使用
server.port=0
同样在/src/main/resources/
中添加application.yml
和
server:
port : 8090