Home > database >  Error resolving template ***, template might not exist or might not be accessible by any of the conf
Error resolving template ***, template might not exist or might not be accessible by any of the conf

Time:07-07

I have spring boot thymeleaf project, if I run project on the Intellij Idea, there is no problem, but When I run jar file, I faced this problem. This is error

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [/login], template might not exist or might not be accessible by any of the configured Template Resolvers

This is errorjpg

CodePudding user response:

it should be easier with some code, but here is a working example with spring boot and Maven.

I have a template called "myTemplate.html" in the folder src/main/resources/templates.

In one of my class I have :

ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);

TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context context = new Context();
//... then here i fill all the variables used in my template

String filledTemplate = templateEngine.process("templates/myTemplate", context);

And everything works as expected

Hope it helps a bit :)

  • Related