Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found 問題排查

來源:互聯網
上載者:User

標籤:init   ror   日誌輸出   ebean   find   using   載入   method   value   

自訂的classLoader啟動spring容器,遇到
Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not subtype (classpath下有類)

Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found(classpath下沒有類)
兩個異常資訊。

這個問題比較詭異,缺少包和沒有包都有問題,有包的情況下報 not subtype(這個應該是classLoader之間的問題,直接調整類的載入策略為雙親委派策略,問題解決),沒包的情況報 not found。只能走上排查之路了。
先根據堆棧進入到源碼,

Caused by: javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
at com.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:165)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:59)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:55)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:338)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.afterPropertiesSet(SqlMapClientFactoryBean.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1648)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1585)
... 38 common frames omitted

xml的解析工具在執行個體化的時候出現了錯誤,比較奇怪的是,其他使用了相同架構的模組並不會出現這個問題。先開啟日誌輸出的參數,在jvm的啟動參數中增加 -Djaxp.debug=true

這個參數開啟之後,可以輸出 DocumentBuilderFactory 在執行個體化時會使用哪個具體的實作類別去執行個體化。


JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: loaded from fallback value: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl using ClassLoader: null

JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using ClassLoader: null

正常的情況下,會優先使用你的配置類。你可以在 systemProperty中配置具體使用哪個類。如果沒有配置,會使用 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl 的實作類別,是jdk8中內建的實作類別。

預設的 fallback類為:com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
注意這一小段代碼,在classpath下尋找fallback類,如果沒有找到,使用預設的fallback類,這個自動在包中搜尋的,所以只要你的包中有相關的實作類別,就會被載入並且執行個體化。

// Try Jar Service Provider Mechanism
T provider = findServiceProvider(type);
if (provider != null) {
return provider;
}

那問題其實已經很明確了,在classpath目錄下找找是不是有相關的類,將相關的依賴包排除掉即可。

<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>

<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>

都讓它使用預設的Factory類。排除掉之後,問題解決。

Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found 問題排查

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.