Java tutorial
/** * This file is part of huborcid. * * huborcid is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * huborcid is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with huborcid. If not, see <http://www.gnu.org/licenses/>. */ package it.cineca.pst.huborcid.config; import org.apache.commons.lang.CharEncoding; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Description; import org.springframework.context.support.ReloadableResourceBundleMessageSource; import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; @Configuration public class ThymeleafConfiguration { private final Logger log = LoggerFactory.getLogger(ThymeleafConfiguration.class); @Bean @Description("Thymeleaf template resolver serving HTML 5 emails") public ClassLoaderTemplateResolver emailTemplateResolver() { ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver(); emailTemplateResolver.setPrefix("mails/"); emailTemplateResolver.setSuffix(".html"); emailTemplateResolver.setTemplateMode("HTML5"); emailTemplateResolver.setCharacterEncoding(CharEncoding.UTF_8); emailTemplateResolver.setOrder(1); return emailTemplateResolver; } @Bean @Description("Spring mail message resolver") public MessageSource emailMessageSource() { log.info("loading non-reloadable mail messages resources"); ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setBasename("classpath:/mails/messages/messages"); messageSource.setDefaultEncoding(CharEncoding.UTF_8); return messageSource; } }