我有一个EAR / WAR文件,应该部署在Websphere Application Server上。 Web应用程序使用spring-web / webmvc。将完整堆栈的spring jar添加到Websphere应用程序服务器类路径中(通过管理)。因此,我只在此Web应用程序WAR文件的WEB-INF / lib中发送1个jar(castor-1.2.jar)文件,因为此应用程序仅需要此文件。类加载策略设置为PARENT_LAST。
spring配置引用一个作为WAR文件的一部分传递的类。
在应用程序启动期间,我得到了一个包含在WEB-INF / lib内的castor-1.2.jar中的类的ClassNotFoundException和NoClassDefFoundError。
任何人都可以解释为什么只要将Spring jar部署到服务器类路径并且castor作为应用程序的一部分提供,类加载器就不会找到castor类?
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 - ...
我能做什么(除了冗余运送与WAR捆绑在一起的弹簧库 - 顺便说一下!)以解决问题?
这是例外:
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
答案 0 :(得分:0)
您需要以下内容:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<!-- Uses Castor for XML -->
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.2</version>
</dependency>
<!-- Castor need this -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>