如何在Spring启动应用程序中配置端口:
@Controlle@EnableAutoConfigurationpublic class SampleController { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController.class, args); }}Spring Boot应用程序中,有两种主要方法可以更改Embedded Tomcat中的端口。
修改application.properties
首先,您可以尝试/ resources文件夹中的application.properties文件:
application.properties文件
修改VM选项
第二种方法,如果你想避免修改任何文件,并检查你只需要在本地的东西,你可以使用vm arg:
转到运行 - >编辑配置 - > VM选项
-Dserver.port=8090用vm arg改变端口
正如文档中所说http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-change-the-http-port
任一组server.port使用命令行选项来JVM中的系统属性--server.port=8090或添加application.properties在/src/main/resources/与
server.port = 8090随机端口使用
server.port=0