首页 > 代码库 > java神奇问题汇总

java神奇问题汇总

com.sun .xml.bind.v2.ContextFactory 类找不到的解决

用cxf+spring发布webservice,使用apache-cxf客户端方式调用接口访问服务器时,报javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory not found 错误,异常堆栈信息如下:


Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory not found
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:151)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:299)
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)
... 65 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:116)
... 70 more

,纠结了很久,各种办法都尝试了,最后才发现是Jre顺序的问题,解决办法如下:

在启动类路径中, Java EE 5 Library 在 JRE System Library[jdk1.6.0_25] 之前, 调整顺序,将JRE放在前面解决。
    有问题的类路径顺序(eclipse:Run->Run Configrations...):