【发布时间】:2015-12-12 16:44:12
【问题描述】:
@Async
public void sendEmail(String to, String subject, WebContext context,String template) throws MessagingException
{
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false, "utf-8");
helper.setTo(to);
helper.setFrom("some.email@mail-server.com");
helper.setSubject(subject);
System.out.println("content1"); //able to see this in console
String content=templateEngine.process(template, context); //problem with this
System.out.println("content2"); // not able to see this in console
helper.setText(content, true);
mailSender.send(mimeMessage);
}
我无法发送带有@Async 注释的电子邮件。当我删除此注释时,电子邮件有效。 @Async 没有使用 Thymeleaf 模板引擎。我将@EnableAsync 放在RootConfig 上,我正在创建bean
有什么想法吗?
【问题讨论】:
-
您是否在应用程序服务器中正确配置了异步,并且您的 web.xml 配置为使用异步?此外,在您的主要帖子中,您有您的电子邮件,请将其删除以避免该帐户上的垃圾邮件。
标签: spring spring-mvc spring-security thymeleaf