java - 从单个tomcat上运行的多个应用程序关闭spring boot应用程序
问题描述
我想在不停止 tomcat 的情况下从单个 tomcat 服务器上运行的多个应用程序以编程方式关闭 spring boot 应用程序。
我在谷歌上搜索了几个解决方案,比如
System.exit(0)
和
SpringbootApplication.exit()
导致关闭tomcat。我不想关闭tomcat。只是特定的应用程序。
我该怎么做..以编程方式有什么方法可以做到这一点。
请帮忙!
解决方案
一种方法是使用致动器。
在您的 pom 中添加此依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在 yml / properties 文件中添加这些属性
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true
management.endpoints.web.exposure.include=*
有了这个,你可以点击这个休息端点来关闭应用程序
http://host:port/actuator/shutdown
这是一个POST调用。如果您在应用程序中使用 Spring Security,那么您可能需要进行一些调整以允许此端点通过。您可以使用 curl 调用 post call
curl -X POST http://host:port/actuator/shutdown
推荐阅读
- indexing - 无法调用链代码名称:“scbcch”,错误:执行事务时超时已过期
- java - 返回令人困惑的布尔语句 - 重构
- powershell - 循环遍历多个 SharePoint 网站集
- c++ - 如何使用 C++ 将 FRED 的经济数据下载到 txt 文件中?
- c# - C# - 无法从 xml 文件中获取节点值
- reactjs - 如何将 componentWillUpdate 更改为 getSnapshotBeforeUpdate
- jestjs - 开玩笑覆盖率:我怎样才能获得覆盖率的总百分比?
- oracle - 无法使用融合 CLI 设置 CLASSPATH:java.sql.SQLException:找不到适合 jdbc:oracle:thin 的驱动程序
- algorithm - 如何制作随机出现墙壁的蛇游戏?
- cypher - AgensGraph 社区版中使用的 Cypher 版本是什么?