当 Spring 尝试创建 AnnotationMethodHandlerAdapter 时,WebSphere 中出现 XSLT ClassCastException
启动 WebSphere 时,我收到此异常:
Could not instantiate bean class [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter]:
Constructor threw exception; nested exception is java.lang.ClassCastException:
com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl incompatible with
javax.xml.transform.TransformerFactory
Caused by: java.lang.ClassCastException: com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl
incompatible with javax.xml.transform.TransformerFactory
at javax.xml.transform.TransformerFactory.newInstance(Unknown Source)
at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.<init>(AbstractXmlHttpMessageConverter.java:47)
at org.springframework.http.converter.xml.SourceHttpMessageConverter.<init>(SourceHttpMessageConverter.java:45)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.<init>(AnnotationMethodHandlerAdapter.java:197)
这似乎对我的 applicationContext.xml 中的任何 bean 没有任何影响,但它仍然很奇怪。对我来说,这看起来好像 IBM 类正在泄漏到我的应用程序中。
我该如何解决这个问题?我已经将选项“访问内部服务器类”设置为“限制”。
When starting WebSphere, I get this exception:
Could not instantiate bean class [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter]:
Constructor threw exception; nested exception is java.lang.ClassCastException:
com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl incompatible with
javax.xml.transform.TransformerFactory
Caused by: java.lang.ClassCastException: com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl
incompatible with javax.xml.transform.TransformerFactory
at javax.xml.transform.TransformerFactory.newInstance(Unknown Source)
at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.<init>(AbstractXmlHttpMessageConverter.java:47)
at org.springframework.http.converter.xml.SourceHttpMessageConverter.<init>(SourceHttpMessageConverter.java:45)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.<init>(AnnotationMethodHandlerAdapter.java:197)
This doesn't seem have any impact on any beans in my applicationContext.xml but it's still odd. For me, this looks as if IBM classes are leaking into my application.
How can I fix this? I already set the option "Access to internal server classes" to "Restrict".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这确实是一个类加载问题,但这不能通过更改类加载器设置来解决。
问题在于 xml-apis 和 javax.xml jar 是通过某些 Maven 依赖项导入的。
由于我们已经将应用程序的类加载器策略设置为 PARENT_LAST,因此 javax.xml.transform.TransformerFactory 是从我们的 jar 文件中的 WebApp 类加载器加载的。
然而,其实现“com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl”来自服务器类加载器,该实现链接到 JDK/JRE 提供的 javax.xml.transform.TransformerFactory。
由于类是从不同的源加载的,所以抛出了 ClassCastException。
删除对 xml-apis / xerces / javax.xml jar 的所有依赖关系解决了问题。
由于这些 API 现在是 JDK 的一部分,因此不再需要导入它们。
...如果你想知道为什么我对这个问题了解这么多:我和亚伦一起工作。 ;)
It was indeed a class-loading issue, however this cannot be solved by changing class-loader settings.
The problem was that the xml-apis and javax.xml jars were being imported over some maven dependencies.
Since we already set the class loader policies for the application to PARENT_LAST, the javax.xml.transform.TransformerFactory was being loaded from the WebApp-Class loader from our jar files.
However its implementation 'com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl' was coming from the server class loader, this one was linked to the javax.xml.transform.TransformerFactory provided by the JDK/JRE.
Since the classes were loaded from different sources a ClassCastException was thrown.
Removing all dependencies to xml-apis / xerces / javax.xml jars solved the problem.
Since these APIs are now part of the JDK they no longer need to be imported.
... and if you wonder why I know so much about this issue: I work together with Aaron. ;)
我不能代表限制,因为我没有个人经验,但我认为问题更多与 IBM 类加载器。您所指的类是 TransformerFactory 的 IBM Java 实现的一部分,我认为您可以尝试以下方法之一来解决此问题:
I can't speak for Restrict as I have no personal experience with it,But I think the problem is more to do with IBM Class Loader. The class you are referring to is part of IBM Java implementation of TransformerFactory, I think you can try one of the following to solve this issue on hand
为什么你说 IBM 类正在泄漏到你的应用程序中?
TransformerFactory 被要求创建一个 newInstance。它遵循一系列步骤来确定要使用哪个 TransformerFactory。如果没有指定任何配置,它只是选择使用默认工厂。
这是 TransformerFactory 的 javadoc:
http://download.oracle .com/javase/1.5.0/docs/api/javax/xml/transform/TransformerFactory.html#newInstance()
操作系统是什么?是AIX吗?
http://www.ibm.com/developerworks/java /jdk/aix/j664/sdkguide.aix64.html
查看 AIX 的此文档(上面的链接),它告诉我这是默认的 Impl:
javax.xml.transform.TransformerFactory
选择 XSLT 处理器。可能的值为:
com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl
使用 XL TXE-J 编译器。该值是默认值。
发回附加信息,以便我们可以尝试解决此问题。
华泰
曼鲁
Why do you say IBM classes are leaking into your application?
The TransformerFactory is asked to create a newInstance. It follows a sequence of steps to determine which TransformerFactory to use. If none of the config is specified, it simply chooses to use the default factory.
Here is the javadoc for TransformerFactory:
http://download.oracle.com/javase/1.5.0/docs/api/javax/xml/transform/TransformerFactory.html#newInstance()
What is the OS ? Is that AIX?
http://www.ibm.com/developerworks/java/jdk/aix/j664/sdkguide.aix64.html
Looking at this doc (link above) for AIX it tells me that this is the default Impl:
javax.xml.transform.TransformerFactory
Selects the XSLT processor. Possible values are:
com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl
Use the XL TXE-J compiler. This value is the default.
Post back additional information so that we can try and troubleshoot this.
HTH
Manglu