使用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模塊屬性重定義可覆蓋父屬性定義的特性,實現屬性值的覆蓋。