ServletContainerInitializer中contextDestroyed()的等效性是什么? [英] what is the equivalence of contextDestroyed() in ServletContainerInitializer?

查看:133
本文介绍了ServletContainerInitializer中contextDestroyed()的等效性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个实现 ServletContextListener的类在Tomcat的初始化或关闭期间添加事件.但是,该类必须位于WEB-INF/lib内的jar文件中.经过阅读后,我发现这是不可能的,替代方法是使用 ServletContainerInitializer .但是,仅onStartup()方法可用.

I have to create a class that implements ServletContextListener to add an event during the initialization or the shutdown of Tomcat. However, the class has to be located in a jar file inside WEB-INF/lib. After doing some readings, I found out that this is not possible, and the alternative is to use ServletContainerInitializer. However, only onStartup() method is available.

在关闭或破坏Web应用程序期间,是否还有其他选择可以添加事件?

Is there any other alternatives where I can also add an event during the shutdown or destruction of the web application?

我正在使用Tomcat 8和Java 8.

I am using Tomcat 8 and Java 8 btw.

推荐答案

让您的ServletContainerInitializer以编程方式添加ServletContextListener,这反过来又会在其contextDestroyed()中完成所需的工作.

Let your ServletContainerInitializer programmatically add a ServletContextListener which in turn does the desired job in its contextDestroyed().

servletContext.addListener(YourServletContextListener.class);

这篇关于ServletContainerInitializer中contextDestroyed()的等效性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆