2012-11-09 36 views
0

我在Apache Tomcat服务器上部署了web应用程序,并且在部署主Web应用程序后需要启动另一个控制台应用程序(套接字服务器)。此套接字服务器与主应用程序具有相同的WAR文件,并且可以访问所有的Web应用程序的Bean和类。
我需要启动后部署的web应用程序启动tomcat(不是在打开应用程序或其他东西的索引页后)
我该怎么做?启动tomcat后执行一些东西

回答

1

您需要实现ServletContextListner接口

public class MyServletContextListener implements ServletContextListener { 

    @Override 
    public void contextDestroyed(ServletContextEvent arg0) { 
    //Notification that the servlet context is about to be shut down. 
    } 

    @Override 
    public void contextInitialized(ServletContextEvent arg0) { 
    // do all the tasks that you need to perform just after the server starts 

    //Notification that the web application initialization process is starting 
    } 

} 

而在你的部署描述符中配置它web.xml

<listener> 
    <listener-class> 
     mypackage.MyServletContextListener 
    </listener-class> 
</listener> 
0

使用的ServletContextListener,你可以在web.xml

你会得到手柄,web应用程序启动时,也当Web应用程序停止配置。

相关问题