WebSphere下的ClassLoader问题
最近做平台移植,原来在Tomcat下的Web应用移植到WebSphere6.1上面。由于应用没有使用流行的MVC框架,而且其中对jsp做了特殊处理,即不使用应用服务器编译页面而是使用jasper自己编译成class保存在本地磁盘再load进来,而WebSphere中的类装载机制比较Tomcat中要严格许多,导致出现以下错误信息:
[06-9-13 16:14:25:691 CST] 00000037 ServletWrappe E SRVE0068E: 未捕获到 servlet SystemDispatcher 的其中一个服务方法中抛出的异常。抛出的异常:java.lang.ClassCastException: com.ibm.ws.classloader.CompoundClassLoader incompatible with java.net.URLClassLoader
at org.apache.jasper.compiler.JspRuntimeContext.<init>(JspRuntimeContext.java:87)
at org.apache.jasper.JspC.initServletContext(JspC.java:910)
at org.apache.jasper.JspC.execute(JspC.java:791)
......
其中SystemDispatcher仅仅是一个页面分发器。看了JspRuntimeContext的源代码,87行是这样的:
parentClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
所以,大概的错误原因,应该是在WebSphere中,Thread.currentThread().getContextClassLoader()返回的是CompoundClassLoader而非URLClassLoader,在控制台中,应用程序的类装入器顺序,选择父类优先或应用程序类优先都是问题依旧。可是我也查过相关资料,WebSphere本身编译页面也是使用Apache的jasper,至少在5.0中是的,难道说在6系列中,WebSphere的页面编译机制变了?否则不是矛盾了吗?