You can add like mentioned in a comment a ServletContextListener
.
public class ServerConfig implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
// Do stuff on startup.
}
public void contextDestroyed(ServletContextEvent event) {
// Do stuff on shutdown.
}
}
Now put the new class on the server side, you also ave to register the Listener in your web.xml file :
<listener>
<listener-class>path.to.class.ServerConfig</listener-class>
</listener>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…