I'm trying to cofigure my project. I have two variants of tempalteResolver. if i use this one:
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(applicationContext);
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(true);
return templateResolver;
}
i get an error that my template can't resolve the thymeleaf syntax th even when i add xmlns:th="http://www.thymeleaf.org"
and when i use the following code:
@Bean
public ClassLoaderTemplateResolver templateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
i get an error that there is no templates under this path (/WEB-INF/templates).
Full path to my templates is src\main\webapp\WEB-INF\templates\
What is the best template resolver to be used and why?
Thanks!
SpringResourceTemplateResolverfor web projects (using SpringMvc controllers), andClassLoaderTemplateResolverfor command line projects, or when you need to generate html for non-web applications (such as sending html email or something like that). - Metroids