Spring Boot - 如何配置端口
问题描述:
寻找如何在Spring启动应用程式中设定连接埠的方式:
Looking for way how to configure port in Spring boot app:
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
这是所有来源:)
答
正如docs http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-change-the-http-port
使用命令行选项将 server.port
设置为系统属性jvm - 服务器.port = 8090
或在 / src / main / resources /
中添加 application.properties
either set server.port
as system property using command line option to jvm --server.port=8090
or add application.properties
in /src/main/resources/
with
server.port = 8090
对于随机端口使用
server.port=0