title: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl while starting the weblogic
body: <p>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.</p>
  
  <pre>
  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
  </pre>
  
  <p>As per our analysis, weblogic is trying to to load its own <code>DocumentBuilderFactoryImpl</code> which is present in <strong>weblogic.jar</strong> instead of apache's xerces. </p>
  
  <p>We tried the following to force the weblogic to load <code>DocumentBuilderFactoryImpl</code> from xerces</p>
  
  <p>i) we have added the following tag into <code>weblogic.xml</code></p>
  
  <pre><code>&lt;prefer-web-inf-classes&gt;true&lt;/prefer-web-inf-classes&gt;
  </code></pre>
  
  <p>ii) we have put latest versions of xalan in jre/lib/endorced folder. this didn't resolve our problem.</p>
  
  <p>ii) we have added entries in weblogic-application.xml</p>
  
  <pre><code>&lt;weblogic-application xmlns="http://www.bea.com/ns/weblogic/90"&gt;
   &lt;application-param&gt;
    &lt;param-name&gt;webapp.encoding.default&lt;/param-name&gt;
    &lt;param-value&gt;UTF-8&lt;/param-value&gt;
   &lt;/application-param&gt;
   &lt;prefer-application-packages&gt;
    &lt;package-name&gt;javax.jws.*&lt;/package-name&gt;
    &lt;package-name&gt;org.apache.xerces.*&lt;/package-name&gt;
    &lt;package-name&gt;org.apache.xerces.jaxp.*&lt;/package-name&gt;
   &lt;/prefer-application-packages&gt;
  &lt;/weblogic-application&gt;
  </code></pre>
  
  <p>ii)Added the following entry in weblogic-application.xml</p>
  
  <pre><code>&lt;xml&gt; 
    &lt;parser-factory&gt; 
      &lt;saxparser-factory&gt;org.apache.xerces.jaxp.SAXParserFactoryImpl&lt;/saxparser-factory&gt; 
      &lt;document-builder-factory&gt;org.apache.xerces.jaxp.DocumentBuilderFactoryImpl&lt;/document-builder-factory&gt; 
      &lt;transformer-factory&gt;org.apache.xalan.processor.TransformerFactoryImpl&lt;/transformer-factory&gt;
    &lt;/parser-factory&gt; 
  &lt;/xml&gt;
  </code></pre>
  
  <p>iii) Added <code>jaxp.properties</code> to load <code>DocumentBuilderFactoryImpl</code> from xerces to the jre/lib and started the server.In this case, the weblogic didnt start.</p>
  
  <p>iv) Then we started the server first and then copied the <code>jaxp.properties</code> file during the run time when server starts.But no success</p>
  
  <p>None of the above worked for us.</p>
  
  <p>Any help is highly appreciated.</p>