本文主要是介绍CXF JAXB 2.0 API jar is being loaded兼容问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS 。这些 Services 可以支持多种协议,比如:SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ,并且可以在多种传输协议上运行,比如:HTTP、JMS 或者 JBI,CXF 大大简化了 Services 的创建,同时它继承了 XFire 传统,一样可以天然地和 Spring 进行无缝集成。
CXF目前在部署的过程中会出现一个很经典的版本问题,那就是java.lang.LinkageError: JAXB 2.0 API jar is being loaded,详细错误大致如下:
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:203) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:93) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:130) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.junit.runner.JUnitCore.run(JUnitCore.java:130) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.wsdl.WSDLManager' defined in class path resource [META-INF/cxf/cxf.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.cxf.wsdl11.WSDLManagerImpl]: Constructor threw exception; nested exception is java.lang.LinkageError: JAXB 2.0 API jar is being loaded (from jar:file:/D:/Works/Sources/Projects/biap/trunk/biap-app/WebRoot/WEB-INF/lib/javaee.jar!/javax/xml/bind/annotation/XmlSchema.class), but this RI (from jar:file:/D:/Works/Sources/Projects/biap/trunk/biap-app/WebRoot/WEB-INF/lib/jaxb-impl-2.1.7.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) requires JAXB 2.1 API jar. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:917) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:873) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:514) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42) at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173) at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:199) ... 14 more Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.cxf.wsdl11.WSDLManagerImpl]: Constructor threw exception; nested exception is java.lang.LinkageError: JAXB 2.0 API jar is being loaded (from jar:file:/D:/Works/Sources/Projects/biap/trunk/biap-app/WebRoot/WEB-INF/lib/javaee.jar!/javax/xml/bind/annotation/XmlSchema.class), but this RI (from jar:file:/D:/Works/Sources/Projects/biap/trunk/biap-app/WebRoot/WEB-INF/lib/jaxb-impl-2.1.7.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) requires JAXB 2.1 API jar. at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:98) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:911) ... 30 more Caused by: java.lang.LinkageError: JAXB 2.0 API jar is being loaded (from jar:file:/D:/Works/Sources/Projects/biap/trunk/biap-app/WebRoot/WEB-INF/lib/javaee.jar!/javax/xml/bind/annotation/XmlSchema.class), but this RI (from jar:file:/D:/Works/Sources/Projects/biap/trunk/biap-app/WebRoot/WEB-INF/lib/jaxb-impl-2.1.7.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) requires JAXB 2.1 API jar. at com.sun.xml.bind.v2.model.impl.ModelBuilder.<clinit>(ModelBuilder.java:173) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:422) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:286) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:117) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:188) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132) at javax.xml.bind.ContextFinder.find(ContextFinder.java:286) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337) at org.apache.cxf.wsdl.JAXBExtensionHelper.createJAXBContext(JAXBExtensionHelper.java:196) at org.apache.cxf.wsdl.JAXBExtensionHelper.getJAXBContext(JAXBExtensionHelper.java:183) at org.apache.cxf.wsdl.JAXBExtensionHelper.addExtensions(JAXBExtensionHelper.java:168) at org.apache.cxf.wsdl.JAXBExtensionHelper.addExtensions(JAXBExtensionHelper.java:88) at org.apache.cxf.wsdl11.WSDLManagerImpl.registerInitialExtensions(WSDLManagerImpl.java:241) at org.apache.cxf.wsdl11.WSDLManagerImpl.registerInitialExtensions(WSDLManagerImpl.java:221) at org.apache.cxf.wsdl11.WSDLManagerImpl.<init>(WSDLManagerImpl.java:110) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:83) ... 32 more |
这个问题由来是因为部署环境中已经存在了一个jaxb2.0的接口,我在CXF次版本号里发现,CXF2.0.X版本都均支持jaxb2.0接口,但CXF2.1.X之后的版本里,将jaxb版本升级到了2.1,但jdk1.5和jdk1.6都还没有升级该版本。解决办法。
用CXF2.1.X以上版本的朋友,要解决JAXB2.0版本升级问题,从根本问题找起,可以用下面方式:jaxb-impl-2.1.7里java com.sun.xml.bind.v2.model.impl. ModelBuilder类中使用到的javax.xml.bind.annotation.XmlSchema接口的location()方法,但这个方法是在javaee中没有提供的,这是在jaxb-api-2.1中提供的。
解决办法,在部署环境里,看看你项目lib下有没有javaee.jar,如果有,删除掉,让javaee从容器加载中获取,这样项目就会先读取CXF2.1.X依赖的jaxb2.1接口了。
有些部署环境可能是正常的,因为javaee在jaxb之后加载了,如果出现这个问题,尝试一下我的解决办法好了。
原创文章,如果转载,请标注作者:田文 CSDN地址:http://blog.csdn.net/tiwen818
这篇关于CXF JAXB 2.0 API jar is being loaded兼容问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!