Several template converters for thimeleaf when loading spring

I am looking for a way to define two pattern solvers that can be used to process thymeleaf mail in a spring boot application. I need this because I have an html template and a text template. Both are required to provide rich text and text content in the letter.

All configuration must be done in the application.properties properties or through the properties of the environment.

I was able to identify only one pattern recognizer:

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 

I would be happy if someone could give me a hint or show me the right direction to find a solution.

+5
source share
1 answer

had the same topic and solved it thanks to the site of thimeleaf. Visit http://www.thymeleaf.org/doc/articles/springmail.html

An example configuration is also provided here:

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

The main method you should learn is as follows:

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

Several template transformers are defined here.

A component is java code, and it is not processed by application.properties. If you find any way to define them in application.properties ... leave a comment.

+1
source

Source: https://habr.com/ru/post/1260984/


All Articles