Musisz zaimplementować interfejs ServletContextListner i wpisać w nim kod, który chcesz uruchomić na starcie systemu tomcat.
Oto krótki opis na ten temat.
ServletContextListner znajduje się w pakiecie javax.servlet.
Oto krótki kod, jak to zrobić.
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
}
}
I trzeba skonfigurować go w deskryptorze wdrożenia web.xml
<listener>
<listener-class>
mypackage.MyServletContextListener
</listener-class>
</listener>
Szukasz czegoś, co nazywa „ServletContextListener”, ma metody, których potrzebujesz. –
Zobacz https://stackoverflow.com/questions/3468150/using-special-auto-start-servlet-to-initialize-on-startup-and-share-application – rogerdpack