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


当前回答

希望这篇文章能有所帮助

application.properties=> 

server.port=8090

application.yml=> 

server
  port:8090

其他回答

由Gradle运行:

在默认端口(8080)运行:./gradlew bootRun 运行在提供的端口(8888):./gradlew bootRun——args='——server.port=8888' 如果应用中有变量。PORT=8888 ./gradlew bootRun . properties文件

由Maven运行:

Run in default port(8080): mvnw spring-boot:run Run in provided port(8888): mvnw spring-boot:run -Dspring-boot.run.jvmArguments='-Dserver.port=8085' Run in provided port(8888): mvn spring-boot:run -Dspring-boot.run.arguments='--server.port=8085' Run in provided port(8888) with other custom property: mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8899 --your.custom.property=custom" If we have any variable in the application.properties file named PORT, run this: SERVER_PORT=9093 mvn spring-boot:run

使用java -jar:

Create the .jar file: For Gradle: ./gradlew clean build. We will find the jar file inside: build/libs/ folder. For Maven: mvn clean install. We will find the jar file inside:target folder. Run in default port(8080): java -jar myApplication. jar Run in provided port(8888): java -jar myApplication.jar --port=8888 Run in provided port(8888): java -jar -Dserver.port=8888 myApplication.jar Run in provided port(8888) having variable SERVER_PORT in application.properties file: SERVER_PORT=8888 java -jar target/myApplication.jar

在应用程序属性中添加一行

server.port = 8090

只需设置环境变量SERVER_PORT。 (这些例子适用于Linux)

使用java -jar启动: SERVER_PORT=9093 java -jar target/eric-sc-dummy.jar 通过maven spring-boot插件启动: SERVER_PORT=9093 mvn spring-boot:run

小贴士:

如果你在java -jar或mvn命令之前添加了其他子命令,那么你需要在一个单独的命令中添加export来设置env,并通过;将它们分开,以确保它对子进程可用。 例句: 出口SERVER_PORT = 9093;export MAVEN_OPTS="-Xmx256m -Xms64m";运行mvn spring-boot:

在Config文件或应用程序属性中配置端口详细信息。

e.g.

port =8876

在我的情况下添加声明

server.port=${port:8081}

覆盖默认的tomcat服务器端口。