I have a webapp which is deploying on tomcat 9. As part of deployment, we just drop the war to the webapps directory and tomcat does the re-deployment of the war. But sometimes we see some error in the logs, basically destroy method of some spring bean is not invoked:
31-Aug-2017 21:41:35.292 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/globalsearch] INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing WebApplicationContext for namespace 'appServlet-servlet': startup date [Wed Aug 30 22:34:34 AEST 2017]; parent: Root WebApplicationContext INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Wed Aug 30 22:34:26 AEST 2017]; root of context hierarchy WARN : org.springframework.beans.factory.support.DisposableBeanAdapter - Invocation of destroy method 'cleanUp' failed on bean with name 'GlobalSearchEventLoadMessageProcessing': java.lang.IllegalStateException: java.io.FileNotFoundException: /opt/tomcat/9.0.0.M19/webapps/globalsearch/WEB-INF/lib/commons-collections-3.2.1.jar (No such file or directory) WARN : org.springframework.beans.factory.support.DisposableBeanAdapter - Invocation of destroy method 'cleanUp' failed on bean with name 'globalSearchMessageSender': java.lang.IllegalStateException: java.io.FileNotFoundException: /opt/tomcat/9.0.0.M19/webapps/globalsearch/WEB-INF/lib/commons-collections-3.2.1.jar (No such file or directory) WARN : org.springframework.beans.factory.support.DisposableBeanAdapter - Invocation of destroy method 'stopServer' failed on bean with name 'globalSearchEmbeddedJMS': java.lang.IllegalStateException: java.io.FileNotFoundException: /opt/tomcat/9.0.0.M19/webapps/globalsearch/WEB-INF/lib/commons-collections-3.2.1.jar (No such file or directory) WARN : org.springframework.beans.factory.support.DisposableBeanAdapter - Invocation of destroy method 'close' failed on bean with name 'connectionFactory': java.lang.IllegalStateException: java.io.FileNotFoundException: /opt/tomcat/9.0.0.M19/webapps/globalsearch/WEB-INF/lib/commons-collections-3.2.1.jar (No such file or directory)
The spring bean is creating a thread which is being destroyed in the destroy method and due to the error this Thread is still active even after re-deploy.
I am using xml file for the spring config:
<bean id="GlobalSearchEventLoadMessageProcessing"
class="xxx.GlobalSearchEventLoadMessageProcessing"
init-method="initialize" destroy-method="cleanUp">
</bean>
How to ensure that destroy method is called and executed completely. I am using Java 8, Tomcat 9 and Spring 4.1.9
PS: I cant stop and start server for deployment process.