![](/img/trans.png)
[英]ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
[英]Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found
我無法解決這個問題。 瀏覽了很多論壇。 請幫忙:
org.springframework.beans.factory.BeanDefinitionStoreException:從ServletContext資源[/WEB-INF/applicationContext.xml]解析XML文檔的意外異常; 嵌套異常是javax.xml.parsers.FactoryConfigurationError:找不到javax.xml.parsers.DocumentBuilderFactory的提供程序。
我已將所有jar文件包含在xerces bin中。 以下是我的WEB-INF / lib結構:
當我們將spring和jpa / hibernate從3升級到4時我們也有這個問題。對我們來說,這是因為hibernate-entitymanager 4.3.11依賴於jdom,它依賴於xml-apis,它將與JRE的rt.jar沖突。 javax.xml的東西。 我們將其排除,以便可以正確解析我們的spring xml配置。 要解決這個問題,我們可以從依賴樹中排除xml-apis。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
我在使用WebSphere Portal 8時遇到了這個問題。我最近使用xalan 2.7.0來訪問和解析XML。
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
刪除xml-apis后(就像Leon Li一樣)它工作正常。
我能夠找到解決方案(瀏覽一些論壇):
轉到JRE所在的位置。 例如,因為我使用的是Websphere Portal JRE,所以我去了這個位置:C:\\ Program Files \\ IBM5 \\ WebSphere \\ AppServer \\ java \\ jre \\ lib
打開jaxb.properties文件並修改屬性javax.xml.parsers.DocumentBuilderFactory以適應您的xml解析器。 在我的例子中是:javax.xml.parsers.DocumentBuilderFactory = org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
我被提升到下一個問題:)。 我現在得到一個ClassCastException。 以下是日志:
從ServletContext資源[/WEB-INF/applicationContext.xml]解析XML文檔時出現意外異常; 嵌套異常是java.lang.ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
歡迎所有幫助。 謝謝
我可以通過設置類加載器應加載xerces jar文件(WAR-> EAR-> Server)的順序來完全解決上述問題。 以下鏈接取自Apache的Xerces站點。 它有助於解決Websphere Portal / WAS的上述問題:
http://www.ibm.com/developerworks/websphere/library/techarticles/0310_searle/searle.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.