2015-11-05 49 views
1

我对thymeleaf很新,但我很喜欢。我遇到了这个问题,这个问题困扰了我很多。 我想在我的Spring Boot应用程序中复制Rich HTML email in Spring with Thymeleaf。我坚持发送一封简单的电子邮件,不是因为发送电子邮件,而是因为templeteEngine.process方法。使用模板引擎的弹簧启动故障

如果我做的:

final String htmlContent = "whatever"; 
message.setText(htmlContent, false); 
javaMailSender.send(mimeMessage); 

我收到的电子邮件correctly.Although做

final String htmlContent = this.templateEngine.process("mail/email-simple.html", ctx); 
message.setText(htmlContent, true /* isHtml */); 
javaMailSender.send(mimeMessage); 

我得到这个错误:

public java.lang.String com.example.controllers.MailController.sendSimpleMail(java.lang.String,java.lang.String,java.util.Locale) throws javax.mail.MessagingException 

更新

[THYMELEAF][qtp320919849-46] Exception processing template "email-simple.html": Error resolving template "email-simple.html", template might not exist or might not be accessible by any of the configured Template Resolvers 

我想这两个选择

@Autowired 
private SpringTemplateEngine templateEngine; 

@Autowired 
private TemplateEngine te; 

我没有使用任何配置,顺便说一句,但我敢肯定这就是问题的所在。 我认为我会通过春季启动独自完成。谢谢

+1

你的“错误”是一个方法签名,而不是一个实际的错误。请提供真实的错误(堆栈跟踪等) –

+0

@SeanPatrickFloyd它不解决我的模板。我使用模板/邮件目录来存储它们。我的控制器确实解决它们。刚刚更新了 – CESCO

+0

这个问题从您使用的示例中:'为了处理我们的模板,我们需要配置我们的TemplateEngine [']'。你做到了吗? –

回答

3

默认情况下,Boot配置的Thymeleaf引擎配置为前缀为/templates/,后缀为.html。不要在模板名称中包含这些位;只需使用"mail/email-simple"即可。