weblogic xml编程 ClassCastException

早上接到项目组发来的java程序接口报错信息。分析其中出错信息如下:

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 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。还在奇怪为什么自己现在才想起来。

 

一切终于平静了。

 

马上写个日志,记录下来。

 

下次希望自己不会再走弯路了。

你可能感兴趣的:(java,编程,xml,Web,weblogic)