ClassCastException while parsing XML with WebLogic

这一生的挚爱 提交于 2019-11-30 08:45:49

It's always the xml-apis.jar. Remove them from your classpath (e.g. remove them from WEB-INF/lib of your webapp).

I think Banang is right. Forum http://forum.springsource.org/showthread.php?t=22597 describes solution for similar problem.

Typically such problems happen when there are several versions of the same class in class path while those versions are loaded by different class loaders. One version of DocumentBuilderFactory was loaded by system class loader, other by class loader of your enterprise application. When you are calling the XML parser the parent's version of the class is used. When you are casting yours private version is utilized. These versions are incompatible that causes ClassCastException.

Remove xml-beans-1.xb2 to the lib directory. Modified the POM so it does not include that jar file with the following:

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

The reason for this issue is you are having multiple jars with same class name in library. Go to WEB-INF/lib and remove xml-apis-1.0.b2.jar and stax-api-1.0.1.jar or remove them from you pom.xml itself and you would be good to go.

I wanted make a slight addition to the previous answers to this question, in the event that anyone else is in the same situation I was. I had the same problem on our WebLogic 9.2 server due to my use of CXF 2.2.3. In addition to the removal of the xml-apis.jar mentioned previously, I also had to remove a xmlParserAPIs library.

As I am using Maven2 it was just a simple matter of adding another inclusion.

    <!-- 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>

Hope this helps someone!

We also has such trouble. The reason of error was in gwt library. Receipe: exlude all gwt client libraries from distr.

As for my case, I managed to solve this issue by removing xml-apis library and also upgrading an XML processing library:

From org.apache.xmlbeans/xmlbeans/2.4.0

Into org.apache.xmlbeans/xmlbeans/2.6.0

FYI, I'm using Weblogic 10.3.6.0.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!