0

我尝试发送带有附件的电子邮件,<form>但出现此错误。我不明白这是什么意思。

    17:11:44,059 ERROR [http-nio-8080-exec-6][render_portlet_jsp:131] null
java.lang.LinkageError: loader constraint violation: when resolving method "javax.mail.internet.MimeBodyPart.setDataHandler(Ljavax/activation/DataHandler;)V" the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) of the current class, org/springframework/mail/javamail/MimeMessageHelper, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, javax/mail/internet/MimeBodyPart, have different Class objects for the type javax/activation/DataHandler used in the signature
        at com.my.sender.Sender.sendEmail(Sender.java:41)
        at com.spring.controller.SpringController.updateFoo(SpringController.java:133)
        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:71)
        at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
        at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:105)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletExceptionAdapter.service(ServletExceptionAdapter.java:68)
        at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
        at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:115)
        at com.liferay.portal.osgi.web.wab.extender.internal.adapter.FilterExceptionAdapter.doFilter(FilterExceptionAdapter.java:46)
        at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(FilterRegistration.java:121)
        at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:45)
        at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:70)
        at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:117)

这是我的代码(所有配置都在 xml 文件中)。

 public boolean sendEmail(Form form) {
    try {
        MimeMessage message = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(EMAIL_SENDER);
        helper.setTo("test@gmail.com");
        helper.setSubject("MY SUBJECT");
        helper.setText("TEST TEXT");

        FileSystemResource file = new FileSystemResource(form.getFile());
        helper.addAttachment(file.getFilename(), file);

        javaMailSender.send(message);

    } catch (MessagingException e) {
        log.error(e.getMessage(), e);
    }
    return false;
}
4

1 回答 1

2

当项目的依赖项产生冲突时会发生此错误!如果您使用的是 Maven,请检查您的 POM 文件。

于 2017-06-09T14:25:20.847 回答