首页 > 解决方案 > 如何使用 Spring Boot 自动释放 8080 端口

问题描述

我正在运行基本的 Spring Boot MVC 应用程序,并且在每次应用程序重新启动时,我必须手动关闭端口 8080,否则 Spring Boot 应用程序将无法运行它给出了这个错误:

Execution failed for task ':DemoApplication.main()'.
> Process 'command 'C:/Program Files/Java/jdk-11.0.3/bin/java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Tomcat不应该在应用关闭后立即关闭并释放8080端口吗?

标签: springspring-mvctomcatserver

解决方案


在 IntelliJ 中,转到 Run / Edit Configurations... / Tomcat Server / Local / Shutdown script ans 指定用于释放端口的脚本。

或者,您可以编辑原始 Tomcat 配置,例如在 处,如下所示d:\dev\apache-tomcat-8.0.36\conf\server.xml<Server port="8080" shutdown="SHUTDOWN">


推荐阅读