【问题标题】:Springboot: need to be informed/notified when Web-Server is UpSpringboot:需要在 Web-Server 启动时被通知/通知
【发布时间】:2019-12-06 05:52:27
【问题描述】:

我正在编写一个将 Tomcat 作为 Web 服务器嵌入的 Springboot 应用程序。

在启动时,我的一些线程已准备好(因此开始执行它们的工作) Tomcat 之前。对于我的许多限制,我希望这些线程在 Tomcat 准备好之前什么都不做

但我不知道如何决定阻止/解除阻止我的线程;为此,我需要了解 Tomcat 的状态。有没有:

  • 提问方式:isWebServerStarted()?
  • 或通过以下消息异步通知的方式:WEB_SERVER_IS_STARTED?

感谢您的帮助

仅供参考,我不想声明我的“私有 ReST 端点” 应用程序可以尝试访问以猜测网络服务器是否 准备好了

【问题讨论】:

标签: java spring spring-boot tomcat


【解决方案1】:

使用ServletContextListener。使用@WebListener 注释您的类,并通过添加@ServletComponentScan 注释告诉spring 配置有关此侦听器的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-17
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    相关资源
    最近更新 更多