3 回答

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊
如果您使用的是 Maven,則可以使用Maven 依賴插件的list目標(biāo):
$ mvn dependency:list -DincludeArtifactIds=thymeleaf
或者使用 Maven 包裝器:
$ ./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
對(duì)于搖籃:
$ 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

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
如果您使用的是 IntelIJ,一個(gè)不錯(cuò)且簡(jiǎn)單的解決方案是單擊 Maven Projects(在右側(cè))并展開依賴項(xiàng)。

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
根據(jù) Spring Docs,您可以使用應(yīng)用程序?qū)傩晕募p松完成此操作。
您可以使用資源過濾從 Maven 項(xiàng)目中自動(dòng)擴(kuò)展屬性。如果您使用 spring-boot-starter-parent,則可以通過 @..@ 占位符引用您的 Maven“項(xiàng)目屬性”
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;
}}
最后,這個(gè)模型屬性可以像任何其他屬性一樣被 Thymeleaf 訪問。使用 th:text 標(biāo)簽,嘗試訪問下面的模型屬性,以便您可以顯示您的應(yīng)用程序正在使用的 Thymeleaf 版本:
${applicationVersion}
添加回答
舉報(bào)