我想以编程方式从单个 tomcat 服务器上运行的多个应用程序关闭 spring boot 应用程序,而不停止 tomcat。
我在 Google 上搜索发现了一些解决方案,例如
System.exit(0)
和
SpringbootApplication.exit()
导致 tomcat 关闭。我不想关闭tomcat。只是特定的应用程序。
我怎样才能做到这一点......以编程方式有什么方法可以做到这一点。
请帮忙!
最佳答案
一种方法是使用执行器。
在您的 pom 中添加此依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
将这些属性添加到您的 yml/属性文件中
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true
management.endpoints.web.exposure.include=*
完成此操作后,您可以点击此休息端点来关闭应用程序
http://host:port/actuator/shutdown
这是一个POST调用。如果您在应用程序中使用 Spring Security,那么您可能需要进行一些调整以允许此端点通过。您可以使用curl来调用post调用,例如
curl -X POST http://host:port/actuator/shutdown
关于java - 从单个 tomcat 上运行的多个应用程序关闭 spring boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58691312/