By default, where does Spring Boot expect views to be stored?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Spring Boot is a widely used framework simplifying the setup and development of new Spring applications. It defaults many configurations, marking it a go-to for developers who value convention over configuration. Among these conventions is the expected location for view templates, which are critical in web applications for rendering HTML content based on data fetched during request handling.
Where Does Spring Boot Expect Views to Be Stored?
In a standard Spring Boot application, the framework expects view templates to be stored within specific directories inside the src/main/resources directory, depending on the templating engine you are using (e.g., Thymeleaf, FreeMarker, Mustache, etc.). Understanding these defaults is key for smooth starting phases in web application development.
Default View Locations:
- Thymeleaf Views:
- Directory:
src/main/resources/templates - Extensions:
.htmlWhen using Thymeleaf as your template engine, Spring Boot looks for template files with an.htmlextension inside thetemplatesdirectory. These templates are then rendered and returned as a response to the client.
- FreeMarker Views:
- Directory:
src/main/resources/templates - Extensions:
.ftlSimilar to Thymeleaf, FreeMarker templates are placed in thetemplatesdirectory. The different file extension (.ftl) indicates that these files are parsed and rendered by the FreeMarker engine.
- Mustache Views:
- Directory:
src/main/resources/templates - Extensions:
.mustacheMustache template files also reside within thetemplatesdirectory, helping to minimize configuration changes when switching between templating languages.
- JSP Views:
- Directory:
src/main/webapp/WEB-INF/jsp - Extensions:
.jspNote that using JSPs requires a traditional servlet container such as Apache Tomcat and proper packaging as a WAR file since JSPs are processed on the server-side.
Here's a summarized table of these defaults:
| Template Engine | Default Directory | File Extension |
| Thymeleaf | src/main/resources/templates | .html |
| FreeMarker | src/main/resources/templates | .ftl |
| Mustache | src/main/resources/templates | .mustache |
| JSP | src/main/webapp/WEB-INF/jsp | .jsp |
Customizing the View Location
Spring Boot offers flexibility allowing developers to change the default view directory path if necessary. This can be done by setting properties in the application.properties or application.yml file.
For example, to change the location of Thymeleaf templates, you can set the following property:
In application.properties:
- Complex project structures.
- Multi-module projects with shared resources.
- Requirement for dynamic template resolution.

