如何使用Spring Boot执行器获取当前服务器时间戳

时间:2019-07-11 18:27:12

标签: java spring-boot-actuator

我正在使用弹簧启动执行器来监视微服务的运行状况。我还需要服务器当前的时间戳。 info /只是返回构建的时间戳。相反,我需要服务器的当前时间戳。

1 个答案:

答案 0 :(得分:0)

请参见https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-application-info-custom

您可以通过提供其他InfoContributor来简单地添加所需的值。

@Component
public class TimeInfoContributor implements InfoContributor {

    @Override
    public void contribute(Info.Builder builder) {
        // Calculate your desired timeValue here.
        builder.withDetail("time", timeValue);
    }

}