使用springboot1.5.x建立项目时,选择使用的thymeleaf时,最终对thymeleaf依赖的版本依然是2.x,想使用3.x版本,其中的一种处理方式是:
在项目的pom.xml中的<properties>段内,重新定义如下的几个属性:
<thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>
<thymeleaf-extras-springsecurity4.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity4.version>
即可实现对thymeleaf3.x的引用。
详细的原因:
1、使用springboot1.5.x建立项目后,默认的模板在pom.xml文件中,会有如下的段:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.20.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
spring-boot-starter-parent-1.5.20.RELEASE.pom依赖的是spring-boot-dependencies-1.5.20.RELEASE.pom的内容,在后者的定义文件(查看地址),可以看到,有关于thymeleaf的属性定义中下:
<thymeleaf.version>2.1.6.RELEASE</thymeleaf.version>
<thymeleaf-extras-springsecurity4.version>2.1.3.RELEASE</thymeleaf-extras-springsecurity4.version> <thymeleaf-extras-conditionalcomments.version>2.1.2.RELEASE</thymeleaf-extras-conditionalcomments.version>
<thymeleaf-layout-dialect.version>1.4.0</thymeleaf-layout-dialect.version>
<thymeleaf-extras-data-attribute.version>1.3</thymeleaf-extras-data-attribute.version>
<thymeleaf-extras-java8time.version>2.1.0.RELEASE</thymeleaf-extras-java8time.version>
2、利用maven模块属性重定义可覆盖父属性定义的特性,实现属性值的覆盖。