我遇到了与那个完全相同的问题:Terminating mvn spring-boot:run doesn't stop tomcat
那里的答案说它只发生在 Windows 上,但实际上并非如此。我正在使用 Intellij 在 OSX 上运行 spring boot,当我停止 spring boot 应用程序时,嵌入式 tomcat 仍在运行。这是 spring boot 教程中的简单示例应用程序。有什么解决办法吗?
最佳答案
我在 MAC 上的 intellij 中遇到了完全相同的问题(spring boot 1.1.6.RELEASE)。
我通过使用 spring boot actuator 解决了这个问题,它提供了一个 rest endpoint (Post) 来关闭应用程序:
localhost:port/shutdown
这可以通过命令行调用:例如curl -X POST localhost:port/shutdown
要启用 spring boot 执行器,请添加以下编译 dep:
org.springframework.boot:spring-boot-starter-actuator
我创建了一个 gradle task bootStop,它确实为我运行了这个 cmd。 你可以在 maven 或者 你可以从 cmd 行调用它(也可以通过 intellij 终端)
特别是如果你想使用调试,你应该将上面给出的 curl cmd 包装在 gradle/maven 任务中。
查看工作示例 (gradle) here
关于spring boot tomcat终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23553018/