spring boot tomcat终止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23553018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
spring boot tomcat termination
提问by kazuar
I have exactly the same issue like that one: Terminating mvn spring-boot:run doesn't stop tomcat
我有完全相同的问题: 终止 mvn spring-boot:run 不会停止 tomcat
The answer there says that it only happens on Windows but it's not actually true. I'm running spring boot on OSX with Intellij and when I stop the spring boot application the embedded tomcat is still running. The is the simple sample app from spring boot tutorial. Any solutions?
那里的答案说它只发生在 Windows 上,但实际上并非如此。我正在使用 Intellij 在 OSX 上运行 spring boot,当我停止 spring boot 应用程序时,嵌入式 tomcat 仍在运行。这是 Spring Boot 教程中的简单示例应用程序。任何解决方案?
采纳答案by Dewfy
I have met the same issue and as result I had to review all solutions on this page and related one. No one is good for me. That is why I have made small research and it is appeared that problems with captured TCP port happen just because neither Gradle nor mvn knows nothing about child manipulation with TCP port.
我遇到了同样的问题,因此我不得不查看此页面和相关页面上的所有解决方案。没有人对我好。这就是为什么我做了一些小的研究,看起来捕获 TCP 端口的问题只是因为 Gradle 和 mvn 都不知道使用 TCP 端口进行子操作。
So instead of killing process just use command:
因此,不要杀死进程,只需使用命令:
$ gradlew –stop
(I hope the same exists for mvn
)
(我希望同样存在mvn
)
This command gracefully closes daemons started by Gradle and frees captured by Tomcat ports.
此命令优雅地关闭由 Gradle 启动的守护进程并释放由 Tomcat 端口捕获的端口。
回答by dasAnderl ausMinga
i have exactly the same issue within intellij on MAC (spring boot 1.1.6.RELEASE).
我在 MAC 上的 Intellij 中遇到了完全相同的问题(spring boot 1.1.6.RELEASE)。
i worked around it by using spring boot actuator which offers a rest endpoint (Post) to shutdown the app:
我通过使用弹簧启动执行器解决了这个问题,它提供了一个休息端点 (Post) 来关闭应用程序:
localhost:port/shutdown
this can be called by commandline: e.g. curl -X POST localhost:port/shutdown
这可以通过命令行调用:例如 curl -X POST localhost:port/shutdown
to enable spring boot actuator add the following compile dep:
要启用 Spring Boot 执行器,请添加以下编译程序:
org.springframework.boot:spring-boot-starter-actuator
i created a gradle task bootStop which does run this cmd for me. you could do the same in maven or you can just call it from cmd line (also trough the intellij terminal)
我创建了一个 gradle 任务 bootStop,它确实为我运行了这个 cmd。你可以在 maven 中做同样的事情,或者你可以从 cmd 行调用它(也可以通过 intellij 终端)
Especially if you want to use debugging, you should wrap the curl cmd given above in a gradle/maven task.
特别是如果你想使用调试,你应该将上面给出的 curl cmd 包装在一个 gradle/maven 任务中。
See working example (gradle) here
在此处查看工作示例(gradle)
回答by Jaskey
Here is a maven example for spring boot actuator to configure HTTP endpoint to shutdown a spring boot web app:
这是 Spring Boot 执行器配置 HTTP 端点以关闭 Spring Boot Web 应用程序的 Maven 示例:
1.Maven Pom.xml:
1.Maven Pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.application.properties:
2.application.properties:
#No auth protected
endpoints.shutdown.sensitive=false
#Enable shutdown endpoint
endpoints.shutdown.enabled=true
All endpoints are listed here:
3.Send a post method to shutdown the app:
3.发送一个post方法来关闭应用程序:
curl -X POST localhost:port/shutdown
回答by FRIVEROS
回答by Daniel Kaplan
A simpler solution is to create a "Spring Boot" configuration and use that to start your app instead of the "Gradle" configuration. The "Spring Boot" configuration does not experience this issue.
一个更简单的解决方案是创建一个“Spring Boot”配置并使用它来启动您的应用程序,而不是“Gradle”配置。“Spring Boot”配置没有遇到这个问题。