如何配置Spring Boot应用程序侦听的TCP/IP端口,使其不使用默认端口8080。
当前回答
您可以在应用程序中配置端口。spring引导项目的资源文件夹中的属性文件。
server.port="port which you need"
其他回答
默认端口号是:8080,但我们可以在application.properties中自定义端口号 如下图所示
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
server.port = 5050 -- #here we can give any port number.
由于Spring Boot提供了各种配置外部化机制(通过各种PropertySource实现和/或按顺序连接到Environment对象的处理器),您可以通过以下方法设置jar存档之外的任何属性:
Pass property through command line argument as application argument java -jar <path/to/my/jar> --server.port=7788 From property in SPRING_APPLICATION_JSON (Spring Boot 1.3.0+) Define environment variable in U*IX shell: SPRING_APPLICATION_JSON='{"server.port":7788}' java -jar <path/to/my/jar> By using Java system property: java -Dspring.application.json='{"server.port":7788}' -jar <path/to/my/jar> Pass through command line argument: java -jar <path/to/my/jar> --spring.application.json='{"server.port":7788}' Define JVM system property java -Dserver.port=7788 -jar <path/to/my/jar> Define OS environment variable U*IX Shell SERVER_PORT=7788 java -jar <path/to/my/jar> Windows SET SERVER_PORT=7788 java -jar <path/to/my/jar> Place property in ./config/application.properties configuration file server.port=7788 and run: java -jar <path/to/my/jar> Place property in ./config/application.yaml server: port: 7788 and run: java -jar <path/to/my/jar> Place property in ./application.properties server.port=7788 and run: java -jar <path/to/my/jar> Place property in ./application.yaml server: port: 7788 and run: java -jar <path/to/my/jar>
您可以将上述方法组合在一起,列表中的前一个配置优先于后一个配置。
例如:
SERVER_PORT=2266 java -Dserver.port=5566 -jar <path/to/my/jar> --server.port=7788
服务器将在端口7788上启动并监听。
这非常有用,在PropertySources中提供优先级较低的默认属性(通常打包在存档中或编码在源代码中),然后在运行时环境中覆盖它。这就是Spring Boot的设计理念:
坚持己见,但当需求开始偏离默认值时,要迅速离开。
SERVER_NAME到server.name的转换由放松绑定完成。
如果你正在处理启动项目,你想要配置端口,你可以在应用程序中输入。属性文件 注意:属性文件应该在src/main/resource下
春天的属性
server.port = 9999 如果您使用CMD,则遵循此命令 -Dserver.port = 9999 对于默认端口,它的server.port=0 确保没有端口正在使用此端口号
如果你正在使用spring命令行接口(CLI),使用——将命令与spring命令参数分开,来更改端口:
春天跑你好。Groovy -- --server.port=9000
spring-boot cli
“服务器。Port =8080"将只工作,如果你运行应用程序作为一个jar通过main方法,
如果您通过tomcat容器将此应用程序作为war文件运行,则此配置将不起作用。
推荐文章
- 在流中使用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