phantom_wizard
phantom_wizard

Reputation: 3168

Spring and Thymeleaf: Template mode "HTML" has not been configured

I'm trying to figure out the spring pet clinic project : https://github.com/spring-projects/spring-petclinic

Trying to make my own basic spring project, want to use thymeleaf and I don't know what is going on because I'm constantly getting error "Template mode "HTML" has not been configured".

I've been trying to learn this by analysing the pet clinic project, then I started lurking through the tutorial: http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html and there is this info about Engines and Resolvers which are not present in pet clinic project.

My question: what the hell is going on here and what steps do I need to run thymeleaf in empty spring project?

Upvotes: 8

Views: 13440

Answers (3)

Wolfgang Fellenz
Wolfgang Fellenz

Reputation: 1

I encountered the same message in my spring boot thymeleaf project. Found out that thymeleaf support had been removed in gradle.properties:

### lib versions ###
serviceBaseVersion=0.12.0
springBootVersion=1.5.14.RELEASE
swaggerVersion=2.6.+
thymeleaf.version=3.0.+
thymeleaf-layout-dialect.version=2.1.+

The last two lines were missing. Fixed that and everything was working again.

Upvotes: 0

phantom_wizard
phantom_wizard

Reputation: 3168

So I've tried everything I could and it turns out that probably the cause for that was that the default thymeleaf parser is for HTML5 (this means that property spring.thymeleaf.mode in application.properties file equals HTML5).

Default application.properties values: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

The line "spring.thymeleaf.mode=HTML" from pet clinic project somehow had no effect on that project, but in mine - it did have. Turns out I was trying to switch default parser into HTML, which I didn't have. This resulted in mentioned error. Deleting or commenting this line in application.properties solved the problem.

Upvotes: 9

dapregala
dapregala

Reputation: 41

Looks like you are not using Spring Boot? That github project (pet-clinic) is made using Spring Boot. In spring boot, almost all configurations are abstracted. Meaning there are already default opinionated configurations out of the box, hidden from the code. These include ViewResolver configurations, that's why you can not see it from the codebase.

Upvotes: 0

Related Questions