2015-11-05 51 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"即可。