Q&A for Work
Setup a private space for you and your coworkers to ask questions and share information.
Learn more about Teams
I need to specify multiple template loader paths for FreeMarker in a Spring Boot web application but the
FreeMarkerAutoConfigurationClass
only let me specify one path using the
spring.freemarker.templateLoaderPath
property, which uses the
setTemplateLoaderPath
method in the
FreeMarkerConfigurationFactory
. However, this class allows me to set multiple path using the
setTemplateLoaderPaths
method. Which is the best way to override this auto-configuration class and specify multiple loader paths? I don't really understand well the Spring Java config classes and I want an example for this before write the code I need. I'm using Spring Boot 1.1.2. Thanks in advance.
You'll need to provide your own bean of type
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
with your desired configuration. To do so, add something similar to the following to one of your application's Java configuration classes:
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPaths("one", "two", "three");
// Apply further configuration as needed
return configurer;
Update: the latest Spring Boot 1.2 snapshots now accept a comma-separated list for the spring.freemarker.templateLoaderPath property allowing you to specify multiple paths without declaring a custom FreeMarkerConfigurer bean.
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0
with attribution required.
rev 2019.8.20.34639