更新时间:2023-11-14 18:52:28
@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>