java - 从单个 tomcat 上运行的多个应用程序关闭 spring boot 应用程序

标签 java spring spring-boot tomcat

我想以编程方式从单个 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/

相关文章:

java - 繁重处理期间的 LibGDX 加载屏幕

java - 使用Java获取XML子元素

java - Spring 乐观锁定 :How to retry transactional method till commit is successful

java - 多种类型的相同接口(interface)

java - org.springframework.beans.NotReadablePropertyException :

java - 如果主服务器在 redis 哨兵配置中关闭,则无法连接到从属计算机,所有这些都在 Docker 容器中运行

java - 如何使用maven for spring-boot在模块之间共享application.properties

java - 当超过 250-300 个用户连接时 Tomcat 停止工作

java - 如何/在哪里在云上托管 Java 服务器?

java - 使用查询字符串搜索对象时,我应该采用什么 Spring 策略?