Java 在启动tomcat之后执行某些操作
我在ApacheTomcat服务器中部署了web应用程序,在部署主web应用程序之后,我需要启动另一个控制台应用程序(套接字服务器)。此套接字服务器与主应用程序位于同一WAR文件中,并且可以访问所有bean和web应用程序类。Java 在启动tomcat之后执行某些操作,java,tomcat,Java,Tomcat,我在ApacheTomcat服务器中部署了web应用程序,在部署主web应用程序之后,我需要启动另一个控制台应用程序(套接字服务器)。此套接字服务器与主应用程序位于同一WAR文件中,并且可以访问所有bean和web应用程序类。 我需要在使用部署的web应用程序启动tomcat之后启动它(而不是在打开应用程序的索引页或其他内容之后) 我如何才能做到这一点?使用ServletContextListener,您可以在web.xml中配置它 当web应用启动和停止时,您将获得句柄。使用ServletCo
我需要在使用部署的web应用程序启动tomcat之后启动它(而不是在打开应用程序的索引页或其他内容之后)
我如何才能做到这一点?使用ServletContextListener,您可以在web.xml中配置它
当web应用启动和停止时,您将获得句柄。使用ServletContextListener,您可以在web.xml中配置它
您将在web应用程序启动和停止时获得句柄。您需要实现
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>
mypackage.MyServletContextListener
您需要实现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>
mypackage.MyServletContextListener