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

javax.activation.DataHandler conflicts in Websphere Liberty 8.5.5.9

所以,这是我上一个问题的故事: 我在 Apache Commons Email and Websphere Liberty Feature JavaMail 1.5 feature 之间存在冲突,我通过使用 <classloader delegation="parentLast" /> 定义应用程序的 jar 加载来解决冲突。

一切正常,直到我按照本教程中所述使用 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 Email and DataHandler in IBM's implementation of IAttachment see javadoc 的一部分,它们是相互冲突的。

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

更新:我的问题还不清楚,但现在我有两个阶段,一个是我使用 <classloader delegation="parentLast" /> 我的邮件工作但文件上传没有'没有 <classloader delegation="parentLast" /> 我的邮件不起作用,但文件上传有效。当我在 WAS Liberty 8.5.5.7 或 8.5.5.8 上部署我的应用程序时它工作正常,问题仅存在于 8.5.5.9

实际上,我已经找到解决此问题的方法。

首先,我将所有包含我的库的依赖项的 scope 更改为 <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>

所以我的 parent 应用程序需要提供所有必需的依赖项,common-emailscommons-iocommons-io 我已经通过 parent 的 pom.xml 添加了关于 commons-email 我已经明确安装了功能 javaMail-1.5,它已经有了这个库。我还删除了:<classloader delegation="parentLast" />

只有一个问题没有解答为什么之前会冲突?如果有人能提供更详细的解释,那就太好了。