Maven 在spring引导/信息端点中显示生成时间
我在spring boot application.yml中配置了以下属性Maven 在spring引导/信息端点中显示生成时间,maven,spring-boot,spring-boot-actuator,spring-boot-maven-plugin,Maven,Spring Boot,Spring Boot Actuator,Spring Boot Maven Plugin,我在spring boot application.yml中配置了以下属性 info: app: name: @project.artifactId@ description: @project.description@ version: @project.version@ timestamp: @timestamp@ 添加Spring启动执行器依赖项后,我可以访问/info端点并查看信息 为了显示时间戳信息,我在maven项目的pom.xml中添加了如下属
info:
app:
name: @project.artifactId@
description: @project.description@
version: @project.version@
timestamp: @timestamp@
添加Spring启动执行器依赖项后,我可以访问/info
端点并查看信息
为了显示时间戳信息,我在maven项目的pom.xml中添加了如下属性:
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
</properties>
${maven.build.timestamp}
yyyy-MM-dd'HH:MM:ss'Z'
时间戳以正确的格式显示,但格式不正确。我的意思是我在IST时区,值显示为,
时间戳:“2017-10-03T16:24:02Z”不正确,可能是以GMT时间格式显示的。但是,我想要IST格式
有人能帮我吗?默认情况下,Maven以UTC格式发出
Maven.build.timestamp
您可以使用的timestamp属性
目标在不同的时区中发出时间戳
下面是一个例子:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>timestamp-property</id>
<goals>
<goal>timestamp-property</goal>
</goals>
<configuration>
<name>build.timestamp.with.offset</name>
<pattern>yyyy-MM-dd'T'HH:mm:ss'Z'</pattern>
<timeZone>IST</timeZone>
</configuration>
</execution>
</executions>
</plugin>
这清楚地表明默认时间戳以UTC为单位,而build.timestamp.with.offset
以IST为单位
因此,您可以使用此插件,然后更新您的
应用程序.yaml
以使用build.timestamp.with.offset
属性。谢谢。有没有办法自动检测时区并以当前时区格式生成数据。@all4u:我不知道。查看默认值,它似乎默认为GMT,除非您提供一个值。您可以更改时间戳属性的行为以满足您的要求。回答:您不需要从应用程序中检索它。properties/yml spring足够聪明,可以处理它。
[INFO] Executing tasks
[echo] [timestamp]: 2017-10-04T08:14:58Z
[echo] [build.timestamp.with.offset]: 2017-10-04T12:44:59Z