优雅关闭在 Spring Boot 应用程序中不起作用

发布于 2025-01-11 13:31:14 字数 647 浏览 0 评论 0原文

我想在现有的 Spring Boot (v2.3.9) 应用程序上激活正常关闭。

最初,为了测试该功能,我创建了一个示例应用程序并添加了属性 application.properties 中的server.shutdown:优雅。当我终止应用程序时,我可以在日志中看到服务器正常关闭。

输入图片此处描述

对输出感到满意,我将相同的属性添加到现有应用程序中。但是,当我终止该特定应用程序时,关闭不会正常发生。不会产生上述日志。这让我想知道该属性是否实际上已设置,因此为了加倍,我还将其设置为运行时参数 -Dserver.shutdown=graceful。在那之后它也没有起作用。

我已确认为现有应用程序运行的 Spring Boot/Tomcat 版本,并且它们高于启用此属性所需的最低版本。

现有的应用程序具有复杂的日志记录结构,其中混合了各种库(log4j、logback 等)。是否可能发生正常关闭但由于日志记录级别较高而导致日志不显示?如果是这种情况,我应该设置/覆盖哪个属性来启用它们。

I want to activate graceful shutdown on an existing Spring Boot (v2.3.9) app.

Initially, to test the feature out, I created a sample app and added the property
server.shutdown: graceful in the application.properties. I could see the server shutting down gracefully in the logs when I kill the app.

enter image description here

Satisfied with the output, I added the same property to the existing app. However, when I kill that particular app, the shutdown doesn't happen gracefully. No logs like above are produced. This made me wonder whether the property was actually getting set so just to double down I also set it as a run-time argument -Dserver.shutdown=graceful. It didn't work even after that.

I have confirmed the Spring Boot/Tomcat versions running for the existing app and they are above the minimum required to enable this property.

The existing application has a convoluted logging structure with a variety of libraries (log4j, logback etc) in the mix. Could it be the case that the graceful shutdown is happening but due to a higher logging level, the logs don't show up? If that's the case, which property should I set/override to enable them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烧了回忆取暖 2025-01-18 13:31:14

这确实是一个日志记录问题。遗留代码深处的日志记录属性覆盖了外部日志级别。关机效果很好。

It was a logging issue indeed. A logging property deep inside the legacy code was overriding the outer log level. The shutdown works just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文