17

我收到以下错误消息:

java.lang.ClassCastException:不能将 weblogic.xml.jaxp.RegistryDocumentBuilderFactory 强制转换为 javax.xml.parsers.DocumentBuilderFactory

我已经通过一些论坛研究这个。他们说要删除xml-apis.jar或 JAR 文件有冲突。但即使我做了所有建议的步骤,我也会遇到同样的错误。

4

7 回答 7

14

它始终是xml-apis.jar. 从你的类路径中删除它们(例如,从你的 webapp 的 WEB-INF/lib 中删除它们)。

于 2011-02-07T21:28:27.833 回答
5

将 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>
于 2014-06-25T07:49:53.400 回答
4

我认为巴南是对的。论坛http://forum.springsource.org/showthread.php?t=22597描述了类似问题的解决方案。

通常,当类路径中有同一类的多个版本而这些版本由不同的类加载器加载时,就会发生此类问题。DocumentBuilderFactory 的一个版本由系统类加载器加载,另一个由企业应用程序的类加载器加载。当您调用 XML 解析器时,将使用该类的父版本。当您投射您的私人版本时,将被使用。这些版本不兼容会导致 ClassCastException。

于 2011-02-07T21:20:27.373 回答
4

此问题的原因是您在库中有多个具有相同类名的 jar。转到 WEB-INF/lib 并删除 xml-apis-1.0.b2.jar 和 stax-api-1.0.1.jar 或从 pom.xml 本身中删除它们,你会很高兴。

于 2014-02-07T21:49:56.640 回答
2

如果其他人处于与我相同的情况,我想对这个问题的先前答案做一点补充。由于我使用 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>

希望这对某人有帮助!

于 2011-05-25T17:41:47.967 回答
1

我们也有这样的烦恼。错误的原因是在 gwt 库中。收据:从发行版中排除所有 gwt 客户端库。

于 2013-05-28T04:59:51.357 回答
0

至于我的情况,我设法通过删除 xml-apis 库并升级 XML 处理库来解决这个问题:

org.apache.xmlbeans/xmlbeans/2.4.0

进入 org.apache.xmlbeans/xmlbeans/2.6.0

仅供参考,我使用的是 Weblogic 10.3.6.0。

于 2016-05-25T03:36:51.197 回答