title: ClassNotFoundException / NoClassDefFoundException with Websphere and Spring
body: <p>I have a EAR/WAR file that shall be deployed on a Websphere Application Server. The web application uses spring-web/webmvc. The full stack of spring jars are added to the Websphere application server classpath (by governance). Therefore I only ship 1 jar (castor-1.2.jar) file in the WEB-INF/lib of this web applications WAR file as this is required only by this application. The class loading policy is set to PARENT_LAST. </p>
  
  <p>The spring config references a class that is deliverd as part of the WAR file.</p>
  
  <p>During application start-up I get and ClassNotFoundException and a NoClassDefFoundError for a class that is contained in the castor-1.2.jar inside the WEB-INF/lib.</p>
  
  <p>Can anyone explain, why the classloader would not find the castor classes as long as Spring jars are deployed to the server class path and castor is shipped as part of the application? </p>
  
  <pre><code>1 - Module - com.ibm.ws.classloader.CompoundClassLoader
        file: ... test-ear.ear/test-war.war/WEB-INF/lib/castor-1.2.jar
  2 - Module - com.ibm.ws.classloader.CompoundClassLoader
  3 - Server-associated - com.ibm.ws.classloader.ExtJarClassLoader
        file: ... clusters/cluster1/custom/classpath/base-lib/spring-webmvc-3.2.9.RELEASE.jar
        ... other spring libraries
  4 - ...
  </code></pre>
  
  <p>What can I do (besides redundantly shipping spring libraries bundled with the WAR - which works by the way!) to resolve the issue?</p>
  
  <p>This is the Exception:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.view.xml.MarshallingView#16799e2d' defined in ServletContext resource [/WEB-INF/castortest-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org.exolab.castor.mapping.MappingException
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
          ... 81 more
  Caused by: java.lang.NoClassDefFoundError: org.exolab.castor.mapping.MappingException
          at java.lang.J9VMInternals.verifyImpl(Native Method)
          at java.lang.J9VMInternals.verify(J9VMInternals.java:93)
          at java.lang.J9VMInternals.prepare(J9VMInternals.java:490)
          at java.lang.Class.getDeclaredConstructors(Class.java:533)
          at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:231)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1002)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:975)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
          ... 83 more
  Caused by: java.lang.ClassNotFoundException: org.exolab.castor.mapping.MappingException
          at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
          at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:204)
          at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:688)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:667)
          at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:119)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:650)
          at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
          at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
          at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:598)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:650)
          ... 97 more
  </code></pre>