如何以编程方式在 spring boot 中向/info 端点添加内容?

问题描述:

如何以编程方式向 Spring Boot 中的 /info 端点添加内容?文档指出这是可能的对于 /health 端点,通过使用 HealthIndicator 接口./info 端点也有一些东西吗?

How do I add things to the /info endpoint in Spring Boot programmatically? The documentation states that this is possible for the /health endpoint through the use of HealthIndicator interface. Is there something for the /info endpoint as well?

我想在那里添加操作系统名称和版本以及其他运行时信息.

I would like to add operating system name and version and other runtime info there.

在 Spring Boot 1.4 中,您可以声明 InfoContributer bean 以使其更容易:

In Spring Boot 1.4, you are able to declare InfoContributer beans to make this a whole lot easier:

@Component
public class ExampleInfoContributor implements InfoContributor {

    @Override
    public void contribute(Info.Builder builder) {
        builder.withDetail("example",
                Collections.singletonMap("key", "value"));
    }

}

http://docs.spring.io/spring-boot/docs/1.4.0.RELEASE/reference/htmlsingle/#production-ready-application-info-custom 了解更多信息.