java.lang.NoClassDefFoundError: org/springframework/orm/jpa/EntityManagerFactoryUtils on shutdown

Recently we faced an issue which occurred on the Ubuntu 14.02. The issue was that undeploy was not working properly. It had exceptions on undeploy about threads not being shutdown. If we tried to shutdown the tomcat afterwards, it just didn’t want to die. The tomcat process was still running even after calling the shutdown.sh script  of tomcat. The same script was working correctly on Ubuntu 12.04.

Here is the error

  
java.lang.NoClassDefFoundError: org/springframework/orm/jpa/EntityManagerFactoryUtils
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:357)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:193)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:498)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:474)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:442)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1066)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1040)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:556)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
And the issue in the end turned out to be the script that was doing the undeploy. The undeploy script was deleting the war file and also the folder to which the war file was extracted to by the tomcat. And while undeploying tomcat was no longer able to find the class files and threw ClassNotFoundException in the PreDestroy methods of spring beans and hence leading to Thread leaking.Solution was to avoid deleting the folder. So we only deleted the war file and rest was done by tomcat itself.
Like this post? Don’t forget to share it!

Leave a Reply

Your email address will not be published. Required fields are marked *