From 7089bd6c42434230e8c08e009cc876a59c91ab0c Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 19 Dec 2018 00:22:36 +0400 Subject: [PATCH] try to fix template resolvers --- .../MailTemplateConfiguration.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java b/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java index 68c201b..5f41117 100644 --- a/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java @@ -1,21 +1,33 @@ package ru.ulstu.configuration; +import nz.net.ultraq.thymeleaf.LayoutDialect; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect; +import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; +import org.thymeleaf.templateresolver.ITemplateResolver; import java.nio.charset.StandardCharsets; @Configuration public class MailTemplateConfiguration { @Bean + public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver, SpringSecurityDialect sec) { + final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); + templateEngine.addTemplateResolver(templateResolver); + templateEngine.addTemplateResolver(emailTemplateResolver()); + templateEngine.addDialect(new LayoutDialect()); + templateEngine.addDialect(sec); + return templateEngine; + } + public ClassLoaderTemplateResolver emailTemplateResolver() { ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver(); - emailTemplateResolver.setPrefix("mail_templates/"); - emailTemplateResolver.setSuffix(".html"); + emailTemplateResolver.setPrefix("/mail_templates/"); emailTemplateResolver.setTemplateMode("HTML5"); emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); - emailTemplateResolver.setOrder(1); return emailTemplateResolver; } + }