我有一个部署在 tomcat 9 上的 webapp。作为部署的一部分,我们只需将 war 放到 webapps 目录中,tomcat 就会重新部署 war。但有时我们会在日志中看到一些错误,基本上没有调用某些 spring bean 的 destroy 方法:
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>
如何确保 destroy 方法被调用并执行完整。 我正在使用 Java 8、Tomcat 9 和 Spring 4.1.9
PS:我无法为部署过程停止和启动服务器。
最佳答案
查看错误,调用了方法:
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)
但它失败了,因为很可能是由于竞争条件——您正在尝试从已从容器中删除的 jar
文件中运行一些代码。你能避免在你的 cleanup
方法中使用外部库吗?
关于java - 在 tomcat 中重新部署应用程序时 Spring bean 没有被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46002949/