【发布时间】:2018-11-05 16:38:37
【问题描述】:
我有一个 Spring Boot 2.1.0.RELEASE 项目。如何查看它使用的 thymeleaf 版本?
【问题讨论】:
-
你在问
Spring Boot Thymeleaf Starter吗?
标签: java spring-boot thymeleaf
我有一个 Spring Boot 2.1.0.RELEASE 项目。如何查看它使用的 thymeleaf 版本?
【问题讨论】:
Spring Boot Thymeleaf Starter 吗?
标签: java spring-boot thymeleaf
如果您使用的是 Maven,则可以使用 list 目标 maven dependency plugin:
$ mvn dependency:list -DincludeArtifactIds=thymeleaf
或者使用 Maven Wrapper:
$ ./mvnw dependency:list -DincludeArtifactIds=thymeleaf
maven 的示例输出:
[INFO] --- maven-dependency-plugin:2.8:list (default-cli) @ site ---
[INFO]
[INFO] The following files have been resolved:
[INFO] org.thymeleaf:thymeleaf:jar:3.0.9.RELEASE:compile
对于Gradle:
$ gradle dependencyInsight --dependency org.thymeleaf:thymeleaf
使用包装器:
$ ./gradlew dependencyInsight --dependency org.thymeleaf:thymeleaf
Gradle 的示例输出:
org.thymeleaf:thymeleaf:2.1.6.RELEASE (selected by rule)
\--- org.thymeleaf:thymeleaf-spring4:2.1.6.RELEASE
\--- org.springframework.boot:spring-boot-starter-thymeleaf:1.5.9.RELEASE
\--- compile
org.thymeleaf:thymeleaf:2.1.4.RELEASE -> 2.1.6.RELEASE
\--- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:1.4.0
\--- org.springframework.boot:spring-boot-starter-thymeleaf:1.5.9.RELEASE
\--- compile
org.thymeleaf:thymeleaf-spring4:2.1.6.RELEASE (selected by rule)
\--- org.springframework.boot:spring-boot-starter-thymeleaf:1.5.9.RELEASE
\--- compile
【讨论】:
The following files have been resolved: org.thymeleaf:thymeleaf:jar:3.0.11.RELEASE:compile
根据 Spring Docs,您可以使用应用程序属性文件轻松完成此操作。
您可以使用 Maven 项目自动扩展属性 资源过滤。如果你使用 spring-boot-starter-parent 你可以 然后通过 @..@ 占位符引用您的 Maven “项目属性”
Maven pom.xml:
<groupId>com.poo</groupId>
<artifactId>gar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Poo</name>
<description>Gar</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
Spring application.properties:
poo.app.version=@project.version@
然后可以使用带有@ControllerAdvice 注解的类将版本作为模型属性注入。
@ControllerAdvice
public class ControllerAdvice {
@Value("${poo.app.version}")
private String applicationVersion;
@ModelAttribute("applicationVersion")
public String getApplicationVersion() {
return applicationVersion;
}}
最后,Thymeleaf 可以像访问其他任何属性一样访问此模型属性。使用 th:text 标签,尝试访问下面的模型属性,以便显示您的应用正在使用的 Thymeleaf 版本:
${applicationVersion}
【讨论】:
<artifactId>spring-boot-starter-thymeleaf</artifactId>没有版本。跨度>