I created an implementation of ServletContextListener and was expecting its contextDestroyed(ServletContextEvent event) method to be invoked AFTER the destroy() method of the single servlet for the web app. The 2.4 servlet spec states: public void contextDestroyed(ServletContextEvent sce) Notification that the servlet context is about to be shut down. All servlets and filters have been destroy()ed before any ServletContextListeners are notified of context destruction. Using Tomcat 5.0.25 and 5.0.27, the servlet destroy() method was invoked AFTER the contextDestroyed() method, in violation of the spec. I tried with and without <load-on-startup> in the web.xml to see if this made a difference, and it did not. NOTE: The order of calls on the initialization side was correct and as I expected. The method contextInitialized(ServletContextEvent event) in my ServletContextListener class was called before the init() methods of my servlet (and filters).
Hmm, it seems you're right. I'm attaching a WAR that shows this behavior. I'm not sure how we haven't detected this in our tests and the Sun TCK tests. I'll ask on tomcat-dev.
Created attachment 12549 [details] A simple WAR showing this (writes to System.out)
Fix committed on TOMCAT_5_0 branch.
This bug seem to have revived in Tomcat 5.5.16 and currently present in Tomcat 5.5.17.
This has been re-fixed in SVN. Thanks for the report.
*** Bug 39038 has been marked as a duplicate of this bug. ***