且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Java Web应用程序取消部署的调用方法

更新时间:2023-11-14 18:52:28

实施 ServletContextListener .

@WebListener
public class LuceneConfig implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        // Do your job here during webapp startup.
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        // Do your job here during webapp shutdown.
    }

}

如果您还没有使用Servlet 3.0(尽管已经使用了2年了),那么您需要删除@WebListener批注,并在web.xml中手动注册它,如下所示:

If you're not on Servlet 3.0 yet (which is already out for 2 years though), then you need to remove the @WebListener annotation and register it manually in web.xml as follows:

<listener>
    <listener-class>com.example.LuceneConfig</listener-class>
</listener>