如何配置Spring Boot应用程序侦听的TCP/IP端口,使其不使用默认端口8080。
当前回答
根据所使用的应用程序配置文件,有三种方法可以做到这一点
a)如果您正在使用应用程序。属性文件集
server.port = 8090
b)如果您正在使用应用程序。yml文件设置YAML格式的服务器端口属性,如下所示
server:
port: 8090
c)也可以在main方法中将属性设置为System属性
System.setProperty("server.port","8090");
其他回答
如果你打算在命令环境中以jar文件的形式运行应用程序,只需输入“SERVER_PORT=***”作为前缀。要执行的完整命令如下所示:
SERVER_PORT=8080 java -jar ***.jar
如果你想在Linux下后台运行应用程序,使用'nohup'命令将如下所示:
SERVER_PORT=8080 nohup java -jar ***.jar &
您可以在下面的方法中添加端口。
执行->配置命令 在application.xml中添加server.port=XXXX
由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
您可以通过更改application.properties来更改服务器配置中的许多其他内容。 比如会话超时,地址和端口等。参考下文
裁判:http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html
我使用了其中的几个,如下所示。
server.session.timeout=1
server.port = 3029
server.address= deepesh
在Spring引导应用程序中,有两种主要方法可以更改嵌入式Tomcat中的端口。
修改application.properties
首先,您可以尝试应用程序。属性文件在/resources文件夹:
server.port = 8090
修改虚拟机选项
第二种方法,如果你想避免修改任何文件和检入你只需要在你的本地文件,你可以使用vm arg:
执行—>编辑配置—>虚拟机选项
-Dserver.port=8090
此外,如果您需要更多信息,可以查看下面的博客文章:在Spring引导应用程序上更改端口
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何找到哪个程序正在使用端口80在Windows?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder