Error resolving template index, template might not exist or might not be accessible by any of the configured Template Resolvers
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
This Spring Boot error means the template engine (usually Thymeleaf) cannot find a template file matching the name returned by your controller. The full error typically reads: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers. The root cause is almost always one of four things: the template file is in the wrong directory, the file extension does not match the resolver configuration, the controller returns a wrong name, or the template engine dependency is missing.
The Error in Context
This happens when your controller returns a view name but Thymeleaf cannot find a matching file.
Fix 1: Put Templates in the Correct Directory
Thymeleaf's default location in Spring Boot is src/main/resources/templates/. The template file must be at:
A controller returning "index" maps to templates/index.html. If your file is at templates/pages/index.html, the controller must return "pages/index".
Fix 2: Check the File Extension
Thymeleaf expects .html files by default. If your template has a different extension, configure it:
If you are using .htm or another extension:
Fix 3: Add the Thymeleaf Dependency
If you do not have the Thymeleaf starter in your project, Spring Boot has no template engine and cannot resolve any templates.
Maven:
Gradle:
Without this dependency, Spring Boot treats the return value as a response body (if @RestController) or fails to find a resolver (if @Controller).
Fix 4: Use @Controller, Not @RestController
@RestController = @Controller + @ResponseBody. It writes the return value directly to the response instead of resolving it as a template name.
Fix 5: Check the Prefix Configuration
If you have customized the template prefix, make sure it matches your directory structure:
Verify the prefix:
Fix 6: Check Case Sensitivity
Template names are case-sensitive on Linux but case-insensitive on macOS and Windows. A template named Index.html works on macOS but fails on a Linux deployment server when the controller returns "index".
Multi-Module and JAR Packaging Issues
When templates are in a separate module or library JAR, they must be on the classpath:
In a multi-module Maven project, ensure the module containing templates is a dependency:
If templates are excluded by the build (e.g., via maven-resources-plugin exclude filters), they will not be in the final artifact.
Debugging Template Resolution
Enable Thymeleaf debug logging to see exactly where it looks for templates:
This produces log output like:
Using Multiple Template Engines
If you have both Thymeleaf and FreeMarker on the classpath, they may conflict. Each engine has its own resolver. Remove the one you are not using, or configure separate prefixes:
Common Pitfalls
- Templates in
static/instead oftemplates/: Thestatic/directory serves files directly (CSS, JS, images). Templates must be intemplates/for Thymeleaf to process them. - Returning a path with leading slash:
return "/index"may fail depending on the resolver configuration. Usereturn "index"(no leading slash). - IDE not copying resources: In IntelliJ, sometimes resources are not copied to the build output. Run
Build > Rebuild Projector checkFile > Project Structure > Modules > Sourcesto ensuresrc/main/resourcesis marked as a resources root. - Spring Boot DevTools caching: Thymeleaf caches templates by default. During development, disable caching so changes are picked up:
spring.thymeleaf.cache=false. - WAR vs JAR packaging: Templates must be in
src/main/resources/templates/for JAR packaging. For WAR, they can also be insrc/main/webapp/WEB-INF/templates/depending on configuration.
Summary
- Templates must be in
src/main/resources/templates/with.htmlextension - Use
@Controller(not@RestController) to resolve view names - Add
spring-boot-starter-thymeleafto your dependencies - Return template names without leading slashes and matching the exact filename case
- Enable
logging.level.org.thymeleaf=DEBUGto see where Thymeleaf looks for templates - Disable template caching during development with
spring.thymeleaf.cache=false

