因此,我之前使用的是带有Sprint Boot 2.0.3的JDK 8,现在转移到了JDK 11和Spring Boot 2.1.1。而且我有一个TemplateEngine
Bean处理了电子邮件的百里香模板,并且在以下ReloadableResourceBundleMessageSource
ReloadableResourceBundleMessageSource messageSourceThymeleafConfiguration = new ReloadableResourceBundleMessageSource();
messageSourceThymeleafConfiguration.setBasename("classpath*:i18n/messages");
messageSourceThymeleafConfiguration.setDefaultEncoding("UTF-8");
现在,我已移至JDK 11和Spring Boot 2.1.1,它突然停止工作,并且在电子邮件中,而不是显示属性文件中基于语言环境的翻译。例如:
??email.greeting_en??
??email.text1_en??
我什至尝试将ReloadableResourceBundleMessageSource
bean替换为ResourceBundleMessageSource
并尝试,但仍然无法正常工作。我试图通过使用classpath:i18n/messages
来插入基本名称字符串,但i18n/messages
似乎还是不起作用。
任何帮助将不胜感激。
编辑:这是我与此相关的整个配置的样子
@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;
}
}