![](/img/trans.png)
[英]Configure multiple template resolvers for a single Spring Boot instance
[英]Multiple template resolvers for thymeleaf on spring boot
我正在寻找一种方法来定义两个模板解析器,可以在spring boot应用程序中用于百万美元的邮件处理。 我需要这个,因为我有一个html模板和一个文本模板。 两者都是在电子邮件中提供富文本和纯文本内容所必需的。
所有配置都应在application.properties中或通过环境属性完成。
我只设法定义了一个模板解析器:
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/mails/
spring.thymeleaf.excluded-view-names=
spring.thymeleaf.view-names=
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=true
如果有人能给我一个提示或向我展示寻找解决方案的正确方向,我会很高兴。
有了相同的主题,并由于百里香的网站解决了它。 访问http://www.thymeleaf.org/doc/articles/springmail.html
这里还有一个配置示例:
您应该研究的主要方法是:
/* ******************************************************************** */
/* THYMELEAF-SPECIFIC ARTIFACTS FOR EMAIL */
/* TemplateResolver(3) <- TemplateEngine */
/* ******************************************************************** */
@Bean
public TemplateEngine emailTemplateEngine() {
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
// Resolver for TEXT emails
templateEngine.addTemplateResolver(textTemplateResolver());
// Resolver for HTML emails (except the editable one)
templateEngine.addTemplateResolver(htmlTemplateResolver());
// Resolver for HTML editable emails (which will be treated as a String)
templateEngine.addTemplateResolver(stringTemplateResolver());
// Message source, internationalization specific to emails
templateEngine.setTemplateEngineMessageSource(emailMessageSource());
return templateEngine;
}
这里定义了多个模板解析器。
con部分是java代码,它不是通过application.properties方式处理的。 如果您在application.properties中找到任何方法来定义它们,请发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.