I'm trying to use Freemarker for e-mail templating in a web application.
I have declared a FreeMarkerConfigurationFactoryBean as follow:
@Bean
public FreeMarkerConfigurationFactoryBean freeMarkerConfigurationFactoryBean(EmailTemplateService templateService) {
FreeMarkerConfigurationFactoryBean configurationFactoryBean = new FreeMarkerConfigurationFactoryBean();
configurationFactoryBean.setPreTemplateLoaders(templateService);
return configurationFactoryBean;
}
When running my JUnit everything is working well, but when running in my webapp my bean is "overriden" by the spring boot FreeMarkerAutoConfiguration.
I have tried to:
But without success. Any idea?
Thanks guys.
As your application is a Web application, it's Spring Boot's FreeMarkerWebConfiguration
that you're interested in. It doesn't use a FreeMarkerConfigurationFactoryBean
but a FreeMarkerConfigurer
. You should create a FreeMarkerConfigurer
bean and configure it as required. For example:
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer(EmailTemplateService templateService) {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setPreTemplateLoaders(templateService);
return configurer;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.