Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
发送带有附件的电子邮件时发生java.lang.LinkageError_Java_Email_Linkageerror - Fatal编程技术网

发送带有附件的电子邮件时发生java.lang.LinkageError

发送带有附件的电子邮件时发生java.lang.LinkageError,java,email,linkageerror,Java,Email,Linkageerror,我试图从发送带有附件的电子邮件,但收到了此错误。我不明白这是什么意思 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/activatio

我试图从
发送带有附件的电子邮件,但收到了此错误。我不明白这是什么意思

    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文件中)


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

 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;
}