Oracle Weblogic: Deployment of Applications Failing with java.lang.ClassCastException
Sometime weblogic throws ClassCastException while application deployment. Below is one of the scenario and steps how go through with this issue.
WebLogic Server deployment of applications using stax classes is failing with a ClassCastException:
To resolve this issue, use the FilteringClassLoader in weblogic.xml (or) weblogic-application.xml descriptor files to load particular classes/packages (in this case, "com.ctc.wstx.stax.*") from the application jar file instead of the system classloader. Below is a snippet of weblogic-application.xml file which has FilteringClassLoader implementation (<prefer-application-packages>) for reference.
Symptoms
WebLogic Server deployment of applications using stax classes is failing with a ClassCastException:
java.lang.ClassCastException: com.ctc.wstx.stax.WstxInputFactory
Cause
This issue was because the customer application uses a different stax jar file version as compared to jar file used by system class loader. Since both have "com.ctc.wstx.stax.WstxInputFactory" as a member, the class is loaded by the system class loader rather than the application class loader, and that is incompatible with its use by the application code.Solution
To resolve this issue, use the FilteringClassLoader in weblogic.xml (or) weblogic-application.xml descriptor files to load particular classes/packages (in this case, "com.ctc.wstx.stax.*") from the application jar file instead of the system classloader. Below is a snippet of weblogic-application.xml file which has FilteringClassLoader implementation (<prefer-application-packages>) for reference.
UTF-8" ?>
<wls:weblogic-application xmlns:wls="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd">
<wls:application-param>
<wls:param-name>webapp.encoding.default</wls:param-name>
<wls:param-value>UTF-8</wls:param-value>
</wls:application-param>
<prefer-application-packages>
<package-name>javax.jws.*</package-name>
<package-name>org.apache.xerces.*</package-name>
<package-name>com.sun.xml.messaging.saaj.*</package-name>
<package-name>com.ctc.wstx.stax.*</package-name>
<package-name>javax.xml.stream.*</package-name>
</prefer-application-packages>
0 Comments