/**
* 自定义监听类,实现LifecycleListener
*/
public class HeerStandardServerLifecycleListener implements LifecycleListener{
@Override
public void lifecycleEvent(LifecycleEvent paramLifecycleEvent) {
String type = "";
if (null != paramLifecycleEvent && null != paramLifecycleEvent.getType()) {
type = paramLifecycleEvent.getType();
}
System.out.println("#################HeerStandardServerLifecycleListener:Tomcat " + type);
}
}
/**
* 在感兴趣的地方加上自定义的监听事件,这里是在StandardServer的构造函数中加上监听器
*/
public StandardServer() {
globalNamingResources = new NamingResourcesImpl();
globalNamingResources.setContainer(this);
HeerStandardServerLifecycleListener heerListenter = new HeerStandardServerLifecycleListener();
addLifecycleListener(heerListenter);
if (isUseNaming()) {
namingContextListener = new NamingContextListener();
addLifecycleListener(namingContextListener);
} else {
namingContextListener = null;
}
}
Tomcat启动后的效果如下: