Home > Enterprise >  Cannot find template location :( please add some templates, check your Thymeleaf configuration, or s
Cannot find template location :( please add some templates, check your Thymeleaf configuration, or s

Time:10-27

I created a spring boot application and while running it I am getting this warning.

2022-10-27 00:35:12.520  WARN 11512 --- [  restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)

Here, you can see my application.properties file

spring.datasource.url=jdbc:mysql://localhost:3306/springbootblogapp? 
createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true
spring.jpa.open-in-view=false

Even though there were some related questions here, the provided answers for them are not working for me, because the warnings mentioned there were a little bit deviated from the warning which I got.

Please help me.

CodePudding user response:

My initial comment, transferred to an answer:

Here is the text of the warning message shown in your question:

2022-10-27 00:35:12.520 WARN 11512 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)

Did you try what the warning message suggests - for example, by adding:

spring.thymeleaf.check-template-location=false 

to your application's config? Or by creating the directory templates mentioned in the warning message (and adding a template there)? By default this directory is expected to be created in the resources location, so that it is on the classpath of the application at runtime.


Update based on your follow-up comment:

Why do you get this warning?

When you create a Spring Boot application, you can choose various additional dependencies (for example by using Spring Initializr).

One such additional dependency is Thymeleaf.

For Maven (assuming you are using Maven), that is the following artifact in your POM:

<artifactId>spring-boot-starter-thymeleaf</artifactId>

There is no point in choosing this option if you don't set up the basic location where you are going to store your Thymeleaf templates.

If you choose to configure the option:

spring.thymeleaf.check-template-location=false

then you are telling Spring not to bother checking if there is a valid configured location for your Thymeleaf templates.

So, even if there is not a valid configured location, you won't see that warning.

If you decide you do want to use Thymeleaf after all, you will need to fix this, by providing that default folder templates on the runtime classpath - or by specifying a custom location via your properties file.


You may see similar warnings (or even errors) with other Spring Boot dependencies you have chosen. For example, if you choose to include the JDBC API, but do not configure a valid data source, then I believe that causes an error (if I recall).

  • Related