Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the equivalence of contextDestroyed() in ServletContainerInitializer?

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.

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

I am using Tomcat 8 and Java 8 btw.

like image 498
r051cky Avatar asked Nov 23 '25 21:11

r051cky


1 Answers

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

servletContext.addListener(YourServletContextListener.class);
like image 55
BalusC Avatar answered Nov 28 '25 07:11

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!