Adding Custom Thymeleaf Template Resolver to Spring Boot
You can add more template resolvers on the TemplateEngine either by invoking the setTemplateResolvers method or by invoking the addTemplateResolver method with your FileTemplateResolver
.
@Configuration
public class ThymeleafExtension {
@Autowired
private SpringTemplateEngine templateEngine;
@PostConstruct
public void extension() {
FileTemplateResolver resolver = new FileTemplateResolver();
resolver.setPrefix("D:\\templates\\");
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML5");
resolver.setOrder(templateEngine.getTemplateResolvers().size());
resolver.setCacheable(false);
templateEngine.addTemplateResolver(resolver);
}
}