一個很讓我鬱悶的java異常

weixin_34162629發表於2011-12-23

今天下午遇到一個很讓我惱火的異常,整了N久也沒有搞出來!雖然知道是包衝突,可是也找不出來原因。

]] Root cause of ServletException.
java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.validation.SchemaFactory.newSchema(Ljavax/xml/transform/Source;)Ljavax/xml/validation/Schema;" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) of the current class, com/geostar/csw/util/JaxbUtil, and the class loader (instance of <bootloader>) for resolved class, javax/xml/validation/SchemaFactory, have different Class objects for the type javax/xml/transform/Source used in the signature
 at com.geostar.csw.util.JaxbUtil.Xml2Object(JaxbUtil.java:122)
 at com.geostar.csw.servlet.CSWServlet.doPost(CSWServlet.java:85)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
 at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
 Truncated. see log file for complete stacktrace
>

其中關鍵的程式碼: at com.geostar.csw.util.JaxbUtil.Xml2Object(JaxbUtil.java:122) 實現如下:

View Code
 1  public  static  Object Xml2Object(Class<?> clazz,InputStream is,InputStream  schema)throws SAXException,JAXBException{
2 Object obj = null ;
3 try{
4 ValidationEventCollector vec = new ValidationEventCollector();
5 SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
6 InputSource inSource=new InputSource(schema);
7 SAXSource sax=new SAXSource(inSource);
8 Schema sch = sf.newSchema(sax); //出錯的地方
9 JAXBContext jc = JAXBContext.newInstance(clazz.getPackage().getName());
10 Unmarshaller u = jc.createUnmarshaller();
11 u.setSchema(sch);
12 u.setEventHandler(vec);
13 obj = u.unmarshal(is);
14 }
15 catch(SAXException e){
16 throw new SAXException(e.getMessage());
17 }catch(JAXBException e){
18 throw new JAXBException(e.getMessage());
19 }
20 return obj;
21 };

其中:Schema型別為:javax.xml.validation.Schema;SchemaFactory為javax.xml.validation.SchemaFactory,JDK為1.6的。不知道怎麼解決這個問題!

汗~~~~~~~~~~~~~~~~。

在網上看了一下,別人說可能和weblogic的包衝突,於是我又配置了一個weblogic.xml

內容如下:

 

View Code
<?xml version="1.0" encoding="UTF-8"?>

<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<jsp-descriptor>
<keepgenerated>true</keepgenerated>
<page-check-seconds>60</page-check-seconds>
<precompile>true</precompile>
<precompile-continue>true</precompile-continue>
</jsp-descriptor>
<container-descriptor>
<optimistic-serialization>true</optimistic-serialization>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

 

相關文章