spring boot 和 thymeleaf 仅用于电子邮件
我有一个可以正常工作的 spring boot 应用程序。
我需要添加一个功能,以便在发生某些操作时发送电子邮件。
我添加了 thymeleaf 代码:
@Configuration
public class ThymeleafTemplateConfig {
@Bean
public SpringTemplateEngine springTemplateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addTemplateResolver(htmlTemplateResolver());
return templateEngine;
}
@Bean
public FileTemplateResolver htmlTemplateResolver() {
FileTemplateResolver emailTemplateResolver = new FileTemplateResolver();
emailTemplateResolver.setPrefix(EMAILS_TEMPLATES_DIRECTORY);
//emailTemplateResolver.setSuffix(".html");
emailTemplateResolver.setTemplateMode("HTML");
emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
return emailTemplateResolver;
}
}
并在处理根 url 的代码下方/
@Controller
public class IndexController {
@RequestMapping("/")
public String index() {
//return "main.xhtml";
return "operation.xhtml";
}
}
当我登录到我的网站时,我重定向到“http://mysiteip/”,并且我已将“设置为映射” / " 是 operation.xhtml 因此,在重定向时或者如果我点击“http://mysiteip/”,则会发生错误。
ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - : - : - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "operation.xhtml", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "operation.xhtml", template might not exist or might not be accessible by any of the configured Template Resolvers
为什么thymeleaf尝试渲染视图?我只想将 thymeleaf 用于电子邮件部分(发送带有 html 正文的电子邮件)。
I have a spring boot application that works correctly.
I need to add a functionality to send emails if certain actions happens.
I have added the thymeleaf code:
@Configuration
public class ThymeleafTemplateConfig {
@Bean
public SpringTemplateEngine springTemplateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addTemplateResolver(htmlTemplateResolver());
return templateEngine;
}
@Bean
public FileTemplateResolver htmlTemplateResolver() {
FileTemplateResolver emailTemplateResolver = new FileTemplateResolver();
emailTemplateResolver.setPrefix(EMAILS_TEMPLATES_DIRECTORY);
//emailTemplateResolver.setSuffix(".html");
emailTemplateResolver.setTemplateMode("HTML");
emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
return emailTemplateResolver;
}
}
and below the code for handling the root url /
@Controller
public class IndexController {
@RequestMapping("/")
public String index() {
//return "main.xhtml";
return "operation.xhtml";
}
}
When I login to my site I redirect to "http://mysiteip/" and I have set as mapping that the "/ " is the operation.xhtml
so at the redirection or if I hit "http://mysiteip/" an error occurs.
ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - : - : - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "operation.xhtml", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "operation.xhtml", template might not exist or might not be accessible by any of the configured Template Resolvers
Why the thymeleaf tries to render the view? I want to use thymeleaf only for the email part (send emails with html body).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论