2011-02-07 66 views
9

我收到以下錯誤信息:ClassCastException異常而解析XML與WebLogic

java.lang.ClassCastException:weblogic.xml.jaxp.RegistryDocumentBuilderFactory不能轉換到javax.xml.parsers.DocumentBuilderFactory中

我已經通過一些研究這個問題的論壇。他們表示要刪除xml-apis.jar或JAR文件存在衝突。但即使我完成了所有建議的步驟,我也遇到了同樣的錯誤。

+1

檢查sotretus答案在這個線程。如果您使用Maven2,它可能適用於您。 http://forum.springsource.org/archive/index.php/t-22597.html – 2011-02-07 20:10:59

+0

您是否驗證過WEB-INF/lib中沒有留下任何jar? – 2011-02-07 20:13:39

回答

4

我認爲巴南是正確的。論壇http://forum.springsource.org/showthread.php?t=22597描述了類似問題的解決方案。

通常,如果在類路徑中存在多個相同類的版本,而這些版本是由不同的類加載器加載的,則會發生此類問題。一個版本的DocumentBuilderFactory由系統類加載器加載,其他類型則由企業應用程序的類加載器加載。在調用XML解析器時,將使用父類的類版本。當你投射你的私人版本被利用。這些版本不兼容導致ClassCastException。

11

它總是xml-apis.jar。將它們從類路徑中移除(例如,從Web應用程序的WEB-INF/lib中移除它們)。

1

我希望對以前對這個問題的回答略作補充,如果其他人處於與我相同的情況。由於使用CXF 2.2.3,我在WebLogic 9.2服務器上遇到同樣的問題。除了前面提到的xml-apis.jar的移除之外,我還必須移除一個xmlParserAPIs庫。

因爲我使用的是Maven2,所以只需添加另一個包含就可以了。

<!-- CXF --> 
    <dependency> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-bundle</artifactId> 
     <version>${dependency.version.cxf}</version> 
     <scope>compile</scope> 
     <exclusions> 
      <exclusion> 
       <artifactId>xml-apis</artifactId> 
       <groupId>xml-apis</groupId> 
      </exclusion> 
      <exclusion> 
       <artifactId>xercesImpl</artifactId> 
       <groupId>xerces</groupId> 
      </exclusion> 
      <exclusion> 
       <artifactId>xmlbeans</artifactId> 
       <groupId>org.apache.xmlbeans</groupId> 
      </exclusion> 
      <exclusion> 
       <artifactId>xmlParserAPIs</artifactId> 
       <groupId>xerces</groupId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

希望這可以幫助別人!

1

我們也有這樣的麻煩。錯誤的原因是在gwt庫中。 Receipe:從distr中排除所有gwt客戶端庫。

2

這個問題的原因是你在庫中有多個具有相同類名的jar。 轉到WEB-INF/lib並刪除xml-apis-1.0.b2.jar和stax-api-1.0.1.jar,或者將它們從pom.xml本身中刪除,這樣你就會很好。

4

將xml-beans-1.xb2移除到lib目錄。修改了POM所以它不包括與下列條件的jar文件:

<dependency> 
    <groupId>xml-apis</groupId> 
    <artifactId>xml-apis</artifactId> 
    <version>1.0.b2</version> 
    <scope>provided</scope> 
</dependency> 
0

至於我的情況,我設法通過刪除XML的API庫,並能升級XML處理庫來解決這個問題:

org.apache.xmlbeans/xmlbeans/2.4.0

進入 org.apache.xmlbeans/xmlbeans/2.6.0

通知你,我使用WebLogic 10.3.6.0。