最近在一个springboot项目里使用thymeleaf模板,访问页面时一直报错。而之前的项目中没发现过这种情况发生。
和之前的项目对比发现,在springboot项目中引入

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

引入的thymeleaf版本居然是2.x.x版本,之前项目引入的是3.x.x版本的
之前项目
该项目

查看相应的pom文件发现,thymeleaf.version确实是2.x.x的。
截图
究竟怎么回事呢?搜索springboot文档中相关thymeleaf的段落,发现了如下描述:
描述

原来在spring-boot-starter-thymeleaf中默认引入的版本thymeleaf2.1,如果需要使用thymeleaf3,需要在pom.xml中加入如下配置:

1
2
3
4
<properties>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>