weblogic部署,常见错误解决二——ClassCastException
3. weblogic使用了自己帶的xml解析器造成的ClassCastException
早上接到項目組發來的java程序接口報錯信息。分析其中出錯信息如下:
1. Warning: Caught exception attempting to use SAX to load a SAX XMLReader???
2. Warning: Exception was: java.lang.ClassCastException: weblogic.apache.xerces.parsers.SAXParser??
3. Warning: I will print the stack trace then carry on using the default SAX parser??
4. java.lang.ClassCastException: weblogic.apache.xerces.parsers.SAXParser??
5.???? at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Ljava.lang.String;)Lorg.xml.sax.XMLReader;(XMLReaderFactory.java:128)??
6.???? at org.xml.sax.helpers.XMLReaderFactory.createXMLReader()Lorg.xml.sax.XMLReader;(XMLReaderFactory.java:96)??
7.???? at org.dom4j.io.SAXHelper.createXMLReader(Z)Lorg.xml.sax.XMLReader;(SAXHelper.java:83)??
8.???? at org.dom4j.io.SAXReader.createXMLReader()Lorg.xml.sax.XMLReader;(SAXReader.java:894)??
9.???? at org.dom4j.io.SAXReader.getXMLReader()Lorg.xml.sax.XMLReader;(SAXReader.java:715)??
10.???? at org.dom4j.io.SAXReader.read(Lorg.xml.sax.InputSource;)Lorg.dom4j.Document;(SAXReader.java:435)??
11.???? at org.dom4j.DocumentHelper.parseText(Ljava.lang.String;)Lorg.dom4j.Document;(DocumentHelper.java:278)
Warning: Caught exception attempting to use SAX to load a SAX XMLReader
Warning: Exception was: java.lang.ClassCastException: weblogic.apache.xerces.parsers.SAXParser
Warning: I will print the stack trace then carry on using the default SAX parser
java.lang.ClassCastException: weblogic.apache.xerces.parsers.SAXParser
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Ljava.lang.String;)Lorg.xml.sax.XMLReader;(XMLReaderFactory.java:128)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader()Lorg.xml.sax.XMLReader;(XMLReaderFactory.java:96)
at org.dom4j.io.SAXHelper.createXMLReader(Z)Lorg.xml.sax.XMLReader;(SAXHelper.java:83)
at org.dom4j.io.SAXReader.createXMLReader()Lorg.xml.sax.XMLReader;(SAXReader.java:894)
at org.dom4j.io.SAXReader.getXMLReader()Lorg.xml.sax.XMLReader;(SAXReader.java:715)
at org.dom4j.io.SAXReader.read(Lorg.xml.sax.InputSource;)Lorg.dom4j.Document;(SAXReader.java:435)
at org.dom4j.DocumentHelper.parseText(Ljava.lang.String;)Lorg.dom4j.Document;(DocumentHelper.java:278)
很明顯是因為weblogic使用了自己帶的xml解析器造成的ClassCastException。這個以前遇到過,以前的解決方法是在web-inf下加一個weblogic.xml使用prefer-web-inf-classes標簽配置weblogic優先使用web程序自帶的類庫。
Xml代碼
1. <?xml version="1.0" encoding="UTF-8"?>
2. <!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
3. <weblogic-web-app>
4.???? <container-descriptor>
5.???????? <prefer-web-inf-classes>true</prefer-web-inf-classes>
6.???? </container-descriptor>
7. </weblogic-web-app>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
結果到自己的程序下面一看,已經放了這個文件了!暈死,咋整的啊。怎么在weblogic8.1中不好使?
就在網上一頓亂找,結果是好使。但是為什么在我們的項目上不好使那,自己一直用的是tomcat做的程序,沒有在weblogic上測試過。沒辦法只好安裝一個,一測試還真是有這個問題。但是看看自己以前的程序就是這么配置的weblogic.xml文件啊。怎么就不好使了那,這個生氣啊。
靜下心,使勁分析weblogic的出錯日志文件(其實就是看看),分析weblogic使用了自己的SAXParser類,在想想類的裝載順序,一直以為weblogic.xml沒有起作用,就沒想到即使起作用了,你自己的web應用程序下的類庫中如果沒有這個SAXParser類,weblogic還是會用自己帶的weblogic.apache.xerces.parsers.SAXParser。
馬上查自己的程序類庫,xml.jar、xmlparserv2.jar,以為所有的關于xml的類都在這兩個文件里。但是打開兩個包一看,沒有。白忙活了好幾個小時。
想起來自己以前解決過這個問題,當時是在程序中加了xerces.jar。還在奇怪為什么自己現在才想起來。
一切終于平靜了。
馬上寫個日志,記錄下來。
下次希望自己不會再走彎路了。
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的weblogic部署,常见错误解决二——ClassCastException的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 要是不会用数据,算什么IT产品经理?
- 下一篇: 大数据之路:阿里巴巴大数据实践,附339