Оснащение ServletContextListener
и зацепить contextDestroyed()
.
Базовый пример:
public class Config implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
// Write code here which should be executed on webapp startup.
}
public void contextDestroyed(ServletContextEvent event) {
// Write code here which should be executed on webapp shutdown.
}
}
и зарегистрируйте его как <listener>
в web.xml
.
<listener>
<listener-class>com.example.Config</listener-class>
</listener>