So, I was using JDK 8 with Sprint Boot 2.0.3 before and now I moved to JDK 11 and Spring Boot 2.1.1. And I had the TemplateEngine
Bean which processed the thymeleaf templates for the email and it was working fine with the below configuration of ReloadableResourceBundleMessageSource
ReloadableResourceBundleMessageSource messageSourceThymeleafConfiguration = new ReloadableResourceBundleMessageSource();
messageSourceThymeleafConfiguration.setBasename("classpath*:i18n/messages");
messageSourceThymeleafConfiguration.setDefaultEncoding("UTF-8");
And now that I have moved to JDK 11 and Spring Boot 2.1.1 it has stopped working all of a sudden and in the emails instead of the locale based translations from the properties file the property keys are being displayed. For example:
??email.greeting_en??
??email.text1_en??
I even tried to replace the ReloadableResourceBundleMessageSource
bean with ResourceBundleMessageSource
and try it and it still doesn't work. I tried to meddle with the base name string by using classpath:i18n/messages
, i18n/messages
still doesn't seem to work.
Any help would be highly appreciated.
Edit: This is how my entire Configuration related to this looks
@Configuration
public class MailServiceThymeleafConfiguration {
@Bean
public TemplateEngine templateEngineThymeleafConfiguration() {
SpringTemplateEngine templateEngineThymeleafConfiguration = new SpringTemplateEngine();
templateEngineThymeleafConfiguration.setTemplateResolver(emailTemplateResolver());
templateEngineThymeleafConfiguration.setMessageSource(messageSourceThymeleafConfiguration());
return templateEngineThymeleafConfiguration;
}
@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("UTF-8");
emailTemplateResolver.setOrder(1);
return emailTemplateResolver;
}
@Bean
public MessageSource messageSourceThymeleafConfiguration() {
ReloadableResourceBundleMessageSource messageSourceThymeleafConfiguration = new ReloadableResourceBundleMessageSource();
messageSourceThymeleafConfiguration.setBasename("classpath*:i18n/messages");
messageSourceThymeleafConfiguration.setDefaultEncoding("UTF-8");
return messageSourceThymeleafConfiguration;
}
}