【发布时间】:2017-01-09 13:58:35
【问题描述】:
我想在我的 htm 页面中显示我的 webapp 的版本,使用类似这样的东西(里面的百里香):
<h4 th:text="${version}">Version</h4>
数据在pom.xml中设置好:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.test.navig</groupId>
<artifactId>navigo</artifactId>
<version>2.0.3-SNAPSHOT</version>
...
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>Application</mainClass>
<addDefaultImplementationEntries>
true
</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
我可以在 MANIFEST.MF 中看到它(在 META-INF 下生成的 jar 中):
实施版本:2.0.3-SNAPSHOT
我尝试在控制器中获取应用程序版本并将其设置在 ModuleAttribute 中:
@ModelAttribute("version")
public String getVersion() {
logger.info("ModelAttribute to get application version");
return getClass().getPackage().getImplementationVersion();
}
但是getClass().getPackage().getImplementationVersion() 的值是null。确实,包 implementationVersion 默认不是应用的 implementation Version。
【问题讨论】:
-
没有确切的答案,但这里有几个链接可能对stackoverflow.com/questions/3697449/…和stackoverflow.com/questions/21045007/…有帮助
-
@RobBaily 在询问之前我已经阅读了它。我尝试的解决方案是我对stackoverflow.com/questions/3697449/…答案的解释
标签: maven spring-boot