Reputation: 4128
I have a Spring-boot application using Thymeleaf as the view engine and I want to use a folder outside the deployed Jar as the source of the Thymeleaf templates, I set the variable:
spring.thymeleaf.prefix=classpath:/templates/
The "/templates/" is next to the Jar with the HTML files but I get an exception that Thymeleaf cannot resolve the templates, I've tried many configurations like:
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.prefix=classpath:templates
etc, not nothing works. What am I doing wrong, it is even possible?
Upvotes: 8
Views: 6898
Reputation: 1
For some reason spring.thymeleaf.prefix=file:./templates/
was not working for me, but I found another way around. I added FileTemplateResolver bean to my configuration:
@Bean
FileTemplateResolver templateResolver() {
FileTemplateResolver resolver = new FileTemplateResolver();
resolver.setPrefix("./templates/");
resolver.setSuffix(".html");
resolver.setCacheable(false);
resolver.setTemplateMode(TemplateMode.HTML);
return resolver;
}
Upvotes: 0
Reputation: 121
spring.thymeleaf.prefix=classpath:/templates/
when returen view name , should be relative path, not start with "/"
Upvotes: 0
Reputation: 4128
OK, looks like the way to do it is setting the value using the file url like this:
spring.thymeleaf.prefix=file:./templates/
It Works now.
Upvotes: 11