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. I would prefer to get notification back to each application once all the applications are started.) I know Spring has the application listener, which can be used once the web application is initialized. But I cannot use it in my case because I would prefer to get a notification once all the web apps are initialized.
******EDITED*******
I've implemented a Tomcat listener to log the message, but I have absolutely no idea where to hook this listener.
I tried to create this bean using Spring and also adding the listener to web.xml both did not work.
Here is my code:
public class KPTomcatListener implements LifecycleListener {
private static final Logger LOG = LoggerFactory.getLogger(KPTomcatListener.class);
/**
* All the events of tomcat
* AFTER_START_EVENT,
* AFTER_STOP_EVENT,
* BEFORE_START_EVENT,
* BEFORE_STOP_EVENT,
* DESTROY_EVENT,
* INIT_EVENT,
* PERIODIC_EVENT,
* START_EVENT,
* STOP_EVENT
*/
private static int counter;
@Override
public void lifecycleEvent(LifecycleEvent arg0) {
String event = arg0.getType();
LOG.debug("Tomcat Envents: " + (++counter) + " :: " + event);
if(event.equals("AFTER_START_EVENT")) {
LOG.debug("Hey I've started");
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…