Callback on Tomcat server startup complete

僤鯓⒐⒋嵵緔 提交于 2019-12-01 21:38:21

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.

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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!