ClassCastException while parsing XML with WebLogic

2019-02-06 11:48发布

I'm getting the following error message:

java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

I've gone through some forums researching this. They said to remove xml-apis.jar or that JAR files were conflicting. But even though I did all the suggested steps, I'm getting the same error.

7条回答
Emotional °昔
2楼-- · 2019-02-06 12:02

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.

查看更多
看我几分像从前
3楼-- · 2019-02-06 12:07

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.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-02-06 12:10

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.

查看更多
等我变得足够好
5楼-- · 2019-02-06 12:14

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

查看更多
我想做一个坏孩纸
6楼-- · 2019-02-06 12:22

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>
查看更多
Juvenile、少年°
7楼-- · 2019-02-06 12:22

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

查看更多
登录 后发表回答