一、坑從何來
ODPS表的資料使用,估計每個後端童靴都會碰到,常用就兩種:
- 将ODPS表清洗後同步到mysql或histore中持久化,然後通過java封裝服務能力調用。這種場景常用于線上實時調用;
2.直接調用ODPS-SDK,通過SQL.run(sql)直接擷取odps資料,次方法常用離線JOB處理資料;
而我這次使用的及時後者,通過SQL直查的方式擷取資料。下面就重點說下碰到一個坑。
二、采坑排查
1.代碼寫完,收工,源碼如下:

2.期待資料日志的列印,此時異常抛出:
3.初步定位傳回資料結果有誤導緻XML解析錯誤,先看看ODPS源碼那行是什麼東東:
問題浮現:多個XML-parser被加載了,但是使用了錯誤的解析器,java8優先使用了自帶的JAXB而不是com.sun.xml.internal.bind.v2.util.XmlFactory導緻的沖突
三、排坑方案
1. 引入三方xml解析包
2.排調間接依賴:xml.xerces
<exclusion>
<groupId> com.alibaba.external</groupId>
<artifactId>xml.xerces</artifactId>
</exclusion>
四、小結
為什麼就用到rt.jar中的xerces類呢,要去看Spring是如何load xml檔案的,其實javadoc裡面說得比較詳細
1、Use the “javax.xml.parsers.DocumentBuilderFactory” system property.
2、Use the properties file "lib/jaxp.properties" in the JRE directory.
3、Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for a classname in the file “META-INF/services/javax.xml.parsers.DocumentBuilderFactory" in jars available to the runtime.
4、Platform default "DocumentBuilderFactory" instance,也就是類com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl。
如果前面三步都找不到實作類,jdk(好像必須是jdk1.5或以上版本)裡自帶的DocumentBuilderFactoryImpl将會被使用