2016-12-08 63 views
5

我正在尋找一種方法來定義兩個模板解析器,可用於春季開機應用中的thymeleaf郵件處理。我需要這個,因爲我有一個html模板和一個文本模板。在電子郵件中提供豐富文本和純文本內容都是必要的。在春季開機上爲thymeleaf多模板解析器

所有配置都應在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 

我會很高興,如果有人可以給我一個提示,或者告訴我正確的方向在哪裏尋找一個解決方案。

回答

1

具有相同的主題,並解決了感謝thymeleaf網站。訪問http://www.thymeleaf.org/doc/articles/springmail.html

這裏也是配置的樣本:

https://github.com/thymeleaf/thymeleafexamples-springmail/blob/3.0-master/src/main/java/thymeleafexamples/springmail/business/SpringMailConfig.java

,你應該考慮的主要方法是這樣:

/* ******************************************************************** */ 
/* 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; 
} 

這裏定義多個模板解析器。

構成部分是,即java代碼,它不通過application.properties方式處理。如果你找到任何方法在application.properties中定義它們,請發表評論。