Loading order of Jax-ws Provider (JAXB)

Source: Internet
Author: User
problem

Use Jax-ws 2.1.4 in your project to throw the following error

Caused By:java.lang.ClassCastException:com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot is cast to Com.sun.xml.internal.bind.api.JAXBRIContext at Com.sun.xml.internal.ws.fault.soapfaultbuilder.<clinit> ( soapfaultbuilder.java:533)Environment-Jax-ws 2.1.4-jdk 1.6.0.22 maven depedency Declaration <!--wsservletcontextlistener--> <dependency> < Groupid>com.sun.xml.ws</groupid> <artifactId>jaxws-rt</artifactId> <version>2.1.4< /version> <type>jar</type> <scope>compile</scope> </dependency> <dependency > <groupId>com.sun.xml.fastinfoset</groupId> <artifactId>FastInfoset</artifactId> < version>1.2.9</version> <type>jar</type> <scope>compile</scope> </dependency > <!--wsservletcontextlistener-->conditionWhen the server-side Web service throws an exception, such as NEP, the client throws the above ClassCastExceptionbackgroundWhy not use JDK's own jax-ws. Because we need to put sevice deploy in Tomcat and use Com.sun.xml.ws.transport.http.servlet.WSServletContextListener. The com.sun.xml.ws.transport.http.servlet.* is part of the Java EE and is not published in the JDK.causesJAX-WS provider is loaded from JDK Rt.jarCom.sun.xml.internal.ws.spi.ProviderImpl, using the class in com.sun.xml.internal.bind.v2.*
While the JAXB context are load from Jaxb-impl-2.1.7.jarcom.sun.xml.bind.v2.ContextFactory, not the JDK

SourceFor the above reasons, one possibility is that the application's lib is joined to the Jaxb-impl.jar without introducing the Jaxws-rt jar and our application has introduced JAXWS-RT (such as the former MAVEN declaration) And Jaxb-impl.jar, in theory, are loaded from the application's dependency pack. After the Epiphany, I found the src folder someone put the following file, specifying JAXB as the implementation of the JDK
|_meta-inf |_services |_ Javax.xml.ws.spi.Provider (Com.sun.xml.internal.ws.spi.ProviderImpl) SolveReomve off the top Meta-inf folder. SummaryMany of the APIs in the JDK use the service Provider Interface (SPI) mechanism, (XML, encryption) JDK to define the upper Contract/api, and provide a default implementation, which itself can provide its own implementation as needed. Generally by the provider class load different implementations. load order of Jax-wsJavax.xml.ws.spi.Provider Provider () If A resource with the name of Meta-inf/services/javax.xml.ws.spi.provider = com . Sun.xml.ws.spi.ProviderImpl $java. Home/lib/jaxws.properties,it contains a entry whose key is Javax.xml.ws.spi.Provider If A system property and the name Javax.xml.ws.spi.Provider Default is loaded (com.sun.xml.inte Rnal.ws.spi.ProviderImpl) Javax.xml.bind.ContextFinder.find jaxb.properties (Key=javax.xml.bind.jaxbcontext) System Property with Name Javax.xml.bind.JAXBContext Meta-inf/services/javax.xml.bind.jaxbcontext the Default is loaded ( Com.sun.xml.internal.bind.v2.ContextFactory)
|_meta-inf |_services |_ javax.xml.bind.JAXBContext (com.sun.xml.bind.v2.ContextFactory)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.