Tomcat application deployment listener

后端 未结 1 2015
逝去的感伤
逝去的感伤 2021-01-14 15:47

I\'m wondering how can I listen for Tomcat web application deployments. I would like to have my listener invoked every time an application is undeployed or deployed from/to

相关标签:
1条回答
  • 2021-01-14 16:44

    servlet context init/destroy

    import org.apache.juli.logging.Log;
    import org.apache.juli.logging.LogFactory;
    
    import javax.servlet.ServletContextListener;
    import javax.servlet.ServletContextEvent;
    
    public class AppContextListener implements ServletContextListener {
    
        private static final Log logger = LogFactory.getLog(AppContextListener.class);
    
        @Override
        public void contextDestroyed(ServletContextEvent e) {
            logger.warn("AppContext Delete: " + e.getServletContext().getContextPath());
        }
    
        @Override
        public void contextInitialized(ServletContextEvent e) {
            logger.warn("AppContext Create: " + e.getServletContext().getContextPath());
        }
    
    }
    

    and put into tomcat/conf/web.xml

       <listener>
         <listener-class>AppContextListener</listener-class>
       </listener>
    
    0 讨论(0)
提交回复
热议问题