ClassDefNotFound for tomcat app with META-INF/context.xml

Have run into an issue where I was getting lots of ClassDefNotFound classloader problems, but only when loading the app via IDEA launcher. If I drop the .war into tomcat and start it the application runs without issue. Also the classes it was saying where not present, where in WEB-INF/lib and the same .war functions (tried resetting my local maven cache anyway - which didn't help).

Turns it this webapp had a META-INF/context.xml file with a loader defintion in it:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <!--
    This setting is for atmosphere, Comet functionality of navigator
    to be able to run under Tomcat
        <Loader className="org.atmosphere.util.AtmosphereClassloader"/>
    -->
   <Loader delegate="true"/>
</Context>



The Loader delegate="true" seems to be causing all the classloader problems when launching inside an embedded tomcat container? is that right? (tomcat 7.0.39 under centos 6.5).

Not sure why this is required here, app seems to have had atmosphere support at some point, I'm not sure if this loader/context is required for this app or not, but IDEA doesn't like it.

2 comments
Comment actions Permalink

To add a few more details to this, the error I get when webapp is deployed is of the kind:

SEVERE: Failure while creating Spring context during startup org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [modules/mif.cfg.xml] fOffending resource: ServletContext resource [/conf/applicationContext-web.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/conf/modules/mif.cfg.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/beans/factory/BeanNameAware      at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)      at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)      at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:218)      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:147)      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:132)      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)      at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)      at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)      at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)      at com.mango.navigator.config.ContextLoaderListener.createWebApplicationContext(ContextLoaderListener.java:36)      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)      at com.mango.navigator.config.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:29)      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)      at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1553)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)      at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)      at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)      at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622)      at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)      at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)      at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)      at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487)      at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97)      at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328)      at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420)      at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)      at sun.rmi.transport.Transport$1.run(Transport.java:177)      at sun.rmi.transport.Transport$1.run(Transport.java:174)      at java.security.AccessController.doPrivileged(Native Method)      at sun.rmi.transport.Transport.serviceCall(Transport.java:173)      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)      at java.lang.Thread.run(Thread.java:744) Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/conf/modules/mif.cfg.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/beans/factory/BeanNameAware      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:202)      ... 63 more Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/BeanNameAware      at java.lang.ClassLoader.defineClass1(Native Method)      at java.lang.ClassLoader.defineClass(ClassLoader.java:800)      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)      at java.security.AccessController.doPrivileged(Native Method)      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)      at java.lang.Class.forName0(Native Method)      at java.lang.Class.forName(Class.java:270)      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1663)      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)      at org.apache.xbean.spring.context.v2c.XBeanQNameHelper.loadClass(XBeanQNameHelper.java:102)      at org.apache.xbean.spring.context.v2c.XBeanQNameHelper.getBeanInfo(XBeanQNameHelper.java:72)      at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.getPropertyDescriptor(XBeanNamespaceHandler.java:576)      at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.addAttributeProperties(XBeanNamespaceHandler.java:328)      at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parseBeanFromExtensionElement(XBeanNamespaceHandler.java:224)      at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parseBeanFromExtensionElement(XBeanNamespaceHandler.java:271)      at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:155)      at org.apache.xbean.spring.context.v2.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:49)      at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1335)      at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1325)      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)      ... 66 more Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.BeanNameAware      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)      at java.security.AccessController.doPrivileged(Native Method)      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)      ... 95 more


This is a Spring-MVC app, so we have all the spring jars in WEB-INF/lib. However we also have cxf-bundle-2.5.1 which I know also contains copies of all the spring jars (albeit slightly different versions). Could the delegate loader be causing these to get confused? of could it be one of the other webapps loaded from the tomcat context? theres no spring jars in tomcat/lib. Or is the delegate context known to cause problems when launching from IDEA.

Not sure why adding the docbase to a tomcat conf/Catalina/localhost/myapp.xml and running same IDEA built artifact manually appears to work without any problems.

0
Comment actions Permalink

Probably not cxf-bundle, I was confused by maven dependency tree that's all. cxf-bundle pom includes the spring jars, but this projects primary pom includes a different version of those same spring jars so takes precedence. That shouldn't affect the deployment stage, not after web exploded artifact has been built.

0

Please sign in to leave a comment.