Callback on Tomcat server startup complete

后端 未结 2 1090
广开言路
广开言路 2021-01-20 01:54

Is there any mechanism, lifecycle event or callbacks, in Spring or Tomcat to notify once Tomcat server startup is completed? (I have 8 web applications and queues configured

相关标签:
2条回答
  • 2021-01-20 02:10

    All of the major Tomcat components implement org.apache.catalina.Lifecycle which includes the ability to add a org.apache.catalina.LifecycleListener. It sounds like you want the AFTER_START_EVENT of the Host.

    You configure the listener in server.xml like this:

    <Host ... >
      <Listener className="your.package.KPTomcatListener"/>
      <!-- Other nested elements go here -->
    </Host>
    

    The class must be packaged in a JAR and the JAR placed in Tomcat's lib directory.

    0 讨论(0)
  • 2021-01-20 02:21

    In case someone wants to do it programmatically (if using embedded Tomcat for example):

    Tomcat tomcat = new Tomcat();
    ...
    tomcat.getServer().addLifecycleListener(new KPTomcatListener());
    tomcat.start()
    
    0 讨论(0)
提交回复
热议问题