小编tom*_*ani的帖子

如何使 Spring Boot 应用程序在 tomcat 失败时退出

我们有一堆基于 Spring Boot 2.5.4 的微服务,还包括spring-kafka:2.7.6spring-boot-actuator:2.5.4。所有服务都使用 Tomcat 作为 servlet 容器并启用正常关闭。这些微服务使用 docker 进行容器化。
由于配置错误,昨天我们在其中一个容器上遇到了问题,因为它占用了另一个容器已绑定的端口。
日志状态:

Stopping service [Tomcat]
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 8080 was already in use.
Run Code Online (Sandbox Code Playgroud)

然而,由于 kafka 消费者/流的存在,JVM 仍在运行。

我需要销毁所有东西,或者至少做一个System.exit(error-code)来触发 docker 重启策略。我怎样才能实现这个目标?如果可能,使用配置的解决方案比需要开发的解决方案更好。

我开发了一个由SpringBootApplicationKafkaConsumer类组成的最小测试应用程序,以确保问题与我们的微服务无关。相同的结果。

POM文件

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.5.4</version>
  <relativePath/> <!-- lookup parent from …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-boot spring-kafka

6
推荐指数
1
解决办法
338
查看次数

标签 统计

spring-boot ×1

spring-kafka ×1

spring-mvc ×1