• ClassNotFoundException:com.sun.xml.bind.v2.ContextFactory


    项目中引入hive-jdbc-1.2.1-standalone.jar包之后,报错如下:

    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

    网上找了各种解决办法均不对症,最终跟代码发现在执行如下代码时会异常:

    JAXBContext.newInstance(...)

    一步步跟进内部代码,找到COntextFinder类中的find方法,可以看到一路在search javax.xml.bind.JAXBContext,大概查找路径如下:

    1、从jaxb.properties中查找

    2、从system property中查找

    3、OSGi search

    4、search META-INF services

    5、最后,以上全找不到,则使用默认的com.sun.xml.internal.bind.v2.ContextFactory

    在打断点的过程,发现第四步时,在resourceURL中看到了hive-jdbc-1.2.1-standalone.jar的路径,于是看了下hive-jdbc-1.2.1-standalone.jar包的META-INF的service路径下,确实有关于javax.xml.bind.JAXBContext的配置

    原因找到了,解决办法很简单:

    要么增加jar包,让程序能找到这个类com.sun.xml.bind.v2.ContextFactory;要么使用默认的。

    我的简单粗暴的办法是,把hive-jdbc-1.2.1-standalone.jar包META-INF的service下javax.xml.bind.JAXBContext的配置删掉。替换jar包重启服务就解决报错问题了

    未解决我问题的文章,供参考:

    http://blog.sina.com.cn/s/blog_6f282fba0101iqn7.html

    https://blog.csdn.net/ninetowns2008/article/details/40741831

    https://blog.csdn.net/hadues/article/details/79188793

  • 相关阅读:
    Android布局控件
    XAMPP里tomcat启动报错:Make sure you have Java JDK or JRE installed and the required ports are free
    poj 北京大学 2014研究生推免上机考试(校内)
    2014北大计算机学科保研直博夏令营上机poj考试
    《C++Primer》第四版学习笔记--持续更新中
    poj1986:Distance Queries
    poj2533:最长上升子序列
    poj1062:昂贵的聘礼
    黑书贪心例题之钓鱼 poj1042:Gone Fishing
    转:最小没出现的整数
  • 原文地址:https://www.cnblogs.com/aligege/p/10628325.html
Copyright © 2020-2023  润新知