Websphere Liberty 8.5.5.9中的javax.activation.DataHandler冲突

时间:2016-04-06 14:05:46

标签: websphere classloader websphere-liberty server.xml

所以,这是我上一个问题的传奇:javax.mail.NoSuchProviderException: when using Liberty 8.5.5.9 with Apache Commons Email 1.4 我在Apache Commons Email和Websphere Liberty功能JavaMail 1.5 feature之间存在冲突的地方,我通过使用<classloader delegation="parentLast" />定义App的首先加载来解决这个问题。

一切正常,直到我开始实施fileupload,使用本教程中描述的jax-rs 2.0 Configuring a resource to receive multipart/form-data parts from an HTML form submission in JAX-RS 2.0

当我的代码到达以下行时: stream = dataHandler.getInputStream(); streamInputStream的类型,即我试图对DataHandler对象执行某些操作会引发异常:

[ERROR   ] Error occurred during error handling, give up!
loader constraint violation: loader (instance of com/ibm/ws/classloading/internal/ParentLastClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"
[ERROR   ] SRVE0777E: Exception thrown by application class 'org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage:116'
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: loader constraint violation: loader (instance of com/ibm/ws/classloading/internal/ParentLastClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
    at [internal classes]
Caused by: org.apache.cxf.interceptor.Fault: loader constraint violation: loader (instance of com/ibm/ws/classloading/internal/ParentLastClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"
    at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:163)
    ... 1 more
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of com/ibm/ws/classloading/internal/ParentLastClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at com.ibm.ws.classloading.internal.AppClassLoader.definePackageAndClass(AppClassLoader.java:327)
    at [internal classes]
    at ****.EventsAPI.handleUploadedEventForm(EventsAPI.java:174)
    at ****.EventsAPI.postFormData(EventsAPI.java:114)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.ibm.ws.jaxrs20.server.LibertyJaxRsServerFactoryBean.performInvocation(LibertyJaxRsServerFactoryBean.java:636)
    ... 1 more

确实有DataHandler个对象作为Apache Commons EmailDataHandler的一部分,在IBM IAttachment <classloader delegation="parentLast" />的实现中见javadoc,他们是冲突的。

那么,如何解决?可以通过配置解决吗?编写自定义类加载器是不可接受的解决方案。

更新:我的问题并不清楚,但现在我有两个阶段,一个是我使用<classloader delegation="parentLast" />我的邮件工作,但文件上传没有&#39 ; t work和没有content-type我的邮件没有工作,但文件上传工作。当我在WAS Liberty 8.5.5.7或8.5.5.8上部署我的应用程序时它工作正常,问题仅存在于8.5.5.9

1 个答案:

答案 0 :(得分:0)

其实我找到了解决这个问题的方法。

首先,我已将范围更改为包含我的库的所有包含依赖项的<scope>provided</scope>。我再次使用我的库来发送电子邮件,这些邮件依赖于:

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-email</artifactId>
        <version>1.4</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
        <scope>provided</scope>
    </dependency>

因此我的父应用程序需要提供所有必需的依赖项common-emailscommons-iocommons-io我已通过家长的pom.xml添加了有关commons-email我已明确安装了此库的功能javaMail-1.5的内容。我也删除了<classloader delegation="parentLast" />

唯一一个问题仍未解决,为何之前发生冲突?如果有人会提供更详细的解释,那就太棒了。