1

I get the error:

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

This project contains only an IndexController and the index.html which is located resources/templates/index.html

Here's an image of the resource folder structure:

enter image description here

This is the method within the controller:

@RequestMapping(value = {"/", "/home", "/index"})
public String index(){
    return "index";
}
Sid
  • 4,893
  • 14
  • 55
  • 110
Gprice1148
  • 19
  • 6
  • Possible duplicate of [Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers](https://stackoverflow.com/questions/31944355/error-resolving-template-index-template-might-not-exist-or-might-not-be-acces) – kang Nov 01 '18 at 16:06

2 Answers2

0

Try mapping them separately and see if that resolves the issue. Try the following for index.

  @GetMapping("index")
    public String getIndex(){
        return "index"; 
    }

As you can see, I changed the methods name from index to getIndex which makes more sense, naming wise.

Zeusox
  • 7,708
  • 10
  • 31
  • 60
  • B.Still getting the same error with that code. Thanks for the response. – Gprice1148 Nov 01 '18 at 16:32
  • Still nothing.. So weird, i've done a few projects before this with zero issues.. – Gprice1148 Nov 01 '18 at 17:07
  • Could you post the content of your index.html ? – Zeusox Nov 01 '18 at 17:08
  • ` Index

    Index

    `
    – Gprice1148 Nov 01 '18 at 17:11
  • Your first HTML tag should point to thymeleaf. It should look like this: – Zeusox Nov 01 '18 at 17:14
  • Accidentally removed that earlier, but it didn't seem to matter when adding it back. This is odd as i've had plenty of other projects work perfectly. – Gprice1148 Nov 01 '18 at 17:17
  • If your project does not have a lot of code, could you post it all and I will replicate that on my computer to see what is going on ? – Zeusox Nov 01 '18 at 17:18
  • Well, that works just fine on my end. I was able to easily access / /index and /home without any issues... Try a different browser...check your spellings...clear cash...restart your IDE...See if that helps ? – Zeusox Nov 01 '18 at 17:54
  • the issue was the resource folder was in java->com instead of on the same level as the java folder.. what a day. Thanks so much for helping me out a lot – Gprice1148 Nov 01 '18 at 18:14
  • If you think my answer could help future searchers, please upvote it and mark it as correct. I am glad it got solved out ! – Zeusox Nov 01 '18 at 18:18
0

I don't know how are you configuring your Thmeleaf beans, but in oder to use templates located on your templates folder, you should have a similar configuration like the one below.

@Bean
@Description("Thymeleaf template resolver serving HTML 5")
public ClassLoaderTemplateResolver templateResolver() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    // Set prefix should do the trick.
    templateResolver.setPrefix("templates/");
    templateResolver.setCacheable(false);
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode("HTML5");
    templateResolver.setCharacterEncoding("UTF-8");
    return templateResolver;
}

Also, if I am not mistaken, by default the resource package is used as the based folder, so if you add templates, before the /index, it should work.

@RequestMapping(value = {"/", "/home", "/index"})
public String index(){
    return "templates/index";
}
Alain Cruz
  • 4,757
  • 3
  • 25
  • 43