WAS 8.5: java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl 与 javax.xml.parsers.SAXParserFactory 不兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19585014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:33:03  来源:igfitidea点击:

WAS 8.5: java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl incompatible with javax.xml.parsers.SAXParserFactory

javawebsphereclassloaderxerces

提问by David García González

I am deploying a J2EE web application in Websphere Application Server 8.5.

我正在 Websphere Application Server 8.5 中部署 J2EE Web 应用程序。

The web application has a shared library with all the third party libraries. All the internally coded libraries are inside the WEB-INF/lib folder.

Web 应用程序具有与所有第三方库共享的库。所有内部编码的库都在 WEB-INF/lib 文件夹中。

The problem is that in only some jsps WAS it is throwing the following exception.

问题是,只有在某些 jsps WAS 中,它才会抛出以下异常。

I think it is related with xercesImpl-2.8.1.jar but I don't understand why it is throwing this exception and why it is throwing in only some pages.

我认为它与 xercesImpl-2.8.1.jar 相关,但我不明白为什么它会抛出此异常以及为什么它只在某些页面中抛出。

In tomcat it is working perfectly.

在 tomcat 中它运行良好。

java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl incompatible with javax.xml.parsers.SAXParserFactory
    at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source)
    at org.apache.taglibs.standard.tlv.JstlBaseTLV.validate(JstlBaseTLV.java:152)
    at org.apache.taglibs.standard.tlv.JstlCoreTLV.validate(JstlCoreTLV.java:96)
    at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.validateTagLib(ValidateVisitor.java:1129)
    at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.visitJspRootStart(ValidateVisitor.java:491)
    at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:233)
    at com.ibm.ws.jsp.translator.visitor.JspVisitor.visit(JspVisitor.java:216)
    at com.ibm.ws.jsp.translator.JspTranslator.processVisitors(JspTranslator.java:127)
    at com.ibm.ws.jsp.translator.utils.JspTranslatorUtil.translateJsp(JspTranslatorUtil.java:254)
    at com.ibm.ws.jsp.translator.utils.JspTranslatorUtil.translateJspAndCompile(JspTranslatorUtil.java:121)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.translateJsp(AbstractJSPExtensionServletWrapper.java:535)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper._checkForTranslation(AbstractJSPExtensionServletWrapper.java:452)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.checkForTranslation(AbstractJSPExtensionServletWrapper.java:283)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.findWrapper(AbstractJSPExtensionProcessor.java:456)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.getServletWrapper(AbstractJSPExtensionProcessor.java:337)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:963)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1384)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:193)
    at com.ieci.tecdoc.isicres.servlets.QryInitAdvanSearch.doWork(QryInitAdvanSearch.java:209)
    at com.ieci.tecdoc.isicres.servlets.QryInitAdvanSearch.doGet(QryInitAdvanSearch.java:67)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1214)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
    at com.ieci.tecdoc.isicres.filters.URLCheckFilter.doFilter(URLCheckFilter.java:106)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
    at com.ieci.tecdoc.isicres.filters.LoginCheckFilter.doFilter(LoginCheckFilter.java:119)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
    at com.ieci.tecdoc.isicres.filters.XSSFilter.doFilter(XSSFilter.java:72)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
    at com.ieci.tecdoc.isicres.filters.UTF8Filter.doFilter(UTF8Filter.java:65)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:926)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1023)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:522)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:311)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:87)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler.run(ResultHandler.java:905)

采纳答案by UnclickableCharacter

Basically, there is no need to package libraries that implement standardized APIs (like javax.xml) as most of them are already provided either by JRE or application server. This allows for avoiding various incompatibility issues like the one that you face.

基本上,不需要打包实现标准化 API(如javax.xml)的库,因为其中大部分已经由 JRE 或应用程序服务器提供。这可以避免各种不兼容问题,例如您面临的问题。

If you still need to use a specific version of Xerces, change classloading policy of the web module to PARENT_LAST. In this case the library will be picked up from WEB-INF/lib. This does not guarantee you won't have problems though.

如果您仍然需要使用特定版本的 Xerces,请将 Web 模块的类加载策略更改为PARENT_LAST. 在这种情况下,库将从WEB-INF/lib. 但这并不能保证您不会遇到问题。

To sum it up: remove xercesImpl-2.8.1.jarfrom the application. Your operating environment provides XML parser implementation. In most cases you don't need to know which one.

总结一下:xercesImpl-2.8.1.jar从应用程序中删除。您的操作环境提供 XML 解析器实现。在大多数情况下,您不需要知道是哪一个。

回答by David García González

I solved it changing the association of the shared libraries.

我解决了它改变共享库的关联。

Originally the xerces libraries were included as a shared library under application level, so these libraries were loaded before than the application server.

原来xerces库是作为应用层的共享库包含的,所以这些库是在应用服务器之前加载的。

I changed the shared library association to module level, now these libraries are loaded after than the application server and the exception dissappeared.

我将共享库关联更改为模块级别,现在这些库是在应用程序服务器之后加载的,并且异常消失了。

enter image description here

在此处输入图片说明