venkat
venkat

Reputation: 41

java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl while starting the weblogic

As part of our application we are using apache's xerces jaxp parser. When we deploy the application on weblogic 9.2, we are getting the following error.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.wsdl.WSDLManager' defined in class path resource [META-INF/cxf/cxf.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.cxf.wsdl11.WSDLManagerImpl]: Constructor threw exception; nested exception is java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

As per our analysis, weblogic is trying to to load its own DocumentBuilderFactoryImpl which is present in weblogic.jar instead of apache's xerces.

We tried the following to force the weblogic to load DocumentBuilderFactoryImpl from xerces

i) we have added the following tag into weblogic.xml

<prefer-web-inf-classes>true</prefer-web-inf-classes>

ii) we have put latest versions of xalan in jre/lib/endorced folder. this didn't resolve our problem.

ii) we have added entries in weblogic-application.xml

<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
 <application-param>
  <param-name>webapp.encoding.default</param-name>
  <param-value>UTF-8</param-value>
 </application-param>
 <prefer-application-packages>
  <package-name>javax.jws.*</package-name>
  <package-name>org.apache.xerces.*</package-name>
  <package-name>org.apache.xerces.jaxp.*</package-name>
 </prefer-application-packages>
</weblogic-application>

ii)Added the following entry in weblogic-application.xml

<xml> 
  <parser-factory> 
    <saxparser-factory>org.apache.xerces.jaxp.SAXParserFactoryImpl</saxparser-factory> 
    <document-builder-factory>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl</document-builder-factory> 
    <transformer-factory>org.apache.xalan.processor.TransformerFactoryImpl</transformer-factory>
  </parser-factory> 
</xml>

iii) Added jaxp.properties to load DocumentBuilderFactoryImpl from xerces to the jre/lib and started the server.In this case, the weblogic didnt start.

iv) Then we started the server first and then copied the jaxp.properties file during the run time when server starts.But no success

None of the above worked for us.

Any help is highly appreciated.

Upvotes: 4

Views: 18428

Answers (4)

Taras
Taras

Reputation: 487

In my case the problem was that i made a dependency on commons-digester which in turn used another version of xerces (that caused the conflict). So you can review your dependencies in case some other version of xerces was transitively included.

Upvotes: 0

ernesto
ernesto

Reputation: 11

I managed to resolve the issue DocumentBuilderFactory not found with simple solution.

Try to copy xercesImpl.jar to the domain specific lib directory on weblogic MyDomain\servers\MyServer\lib.

Upvotes: 1

MarkoU
MarkoU

Reputation: 329

You could try forcing the use of the specified document builder factory as a command line option:

-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

This is assuming that you have the required Xerces builder factory class in your classpath.

In general, you shouldn't use a separate xerces.jar anymore, unless required by some legacy code. The Xerces parser classes come with the JRE, the package names just start with com.sun.org.apache instead of org.apache. You could try also

-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

and remove xerces.jar from your classpath altogether (this is what we did on WLS 10.3 and Java 1.6).

Upvotes: 1

Pascal Thivent
Pascal Thivent

Reputation: 570545

You did so many things that I don't understand the exact status. My advice would be to strictly follow the Application Server Specific Configuration Guide for WebLogic that I've successfully used in the past with WLS 9.2.

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
    <application-param>
        <param-name>webapp.encoding.default</param-name>
        <param-value>UTF-8</param-value>
    </application-param>
    <prefer-application-packages>
        <package-name>javax.jws.*</package-name>
    </prefer-application-packages>
</weblogic-application>

You'll certainly have to add more packages under prefer-application-packages to setup Weblogic ClassLoader filtering but in the current state of the question, it's impossible to provide a precise answer.


Just in case, you can maybe try to blindly use the weblogic-application.xml from this thread:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
    <xml>
      <parser-factory>
        <saxparser-factory>
          org.apache.xerces.jaxp.SAXParserFactoryImpl
        </saxparser-factory>
        <document-builder-factory>
          org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
        </document-builder-factory>
        <transformer-factory>
          org.apache.xalan.processor.TransformerFactoryImpl
        </transformer-factory>
      </parser-factory>
    </xml>
    <application-param>
        <param-name>webapp.encoding.default</param-name>
        <param-value>UTF-8</param-value>
    </application-param>
    <prefer-application-packages>
        <package-name>javax.jws.*</package-name>
        <package-name>org.apache.xerces.*</package-name>
        <package-name>org.apache.xalan.*</package-name>
    </prefer-application-packages>
</weblogic-application> 

But this is a shot in the dark.

Upvotes: 2

Related Questions