2013-06-28 34 views
15

我不能讓過去的這個問題。瀏覽了很多論壇。請幫助:提供了javax.xml.parsers.DocumentBuilderFactory中無法找到

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found.

我已經包含在Xerces的bin中的所有jar文件。 以下是我的WEB-INF/lib目錄結構:

Lib

+0

[可能重複](http://stackoverflow.com/questions/15526419/unexpected-exception-parsing-xml-document-from-servletcontext-resource-web-inf) – gks

+0

我不確定,但看起來像實施DocumentFactoryBuilder的是沒有發現即使添加了JAR文件後 – Saket

+0

然後用不同的罐子嘗試從[這裏](http://www.findjar.com/class/javax/xml/parsers/DocumentBuilderFactory.html)[用法](HTTP: //grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/javax/xml/parsers/DocumentBuilderFactory.java)[更多信息](HTTP://www.developerfusion。com/code/2064/a-simple-way-to-read -a-xml-file-in-java /) – gks

回答

0

我能夠找到一個解決方案(通過一些論壇瀏覽):

  1. 轉到位置在您的JRE是當下。 例如,由於我使用的是Websphere Portal JRE,因此我去了以下位置:C:\ Program Files \ IBM5 \ WebSphere \ AppServer \ java \ jre \ lib

  2. 打開jaxb.properties文件並修改屬性javax.xml.parsers.DocumentBuilderFactory適用於您的xml解析器。在我的情況是: javax.xml.parsers.DocumentBuilderFactory中= org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

我已晉升到下一個問題:)。我現在正在得到一個ClassCastException。以下是日誌:

從ServletContext的資源出現異常的解析XML文檔[/WEB-INF/applicationContext.xml的]。嵌套的例外是java.lang.ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

所有幫助是值得歡迎的。謝謝

+1

這可能有所幫助。 https://community.jboss.org/thread/152151嘗試從構建中刪除xml-apis.jar。 – austin

11

我們有這個問題也時升級春季和JPA/Hibernate來4.對於我們來說,這是因爲Hibernate-EntityManager的4.3.11對依賴於xml-apis的jdom具有依賴性,這將與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> 
2

我在使用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一樣)後,它工作正常。

相關問題