企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
###46.7.5 编写自定义的InfoContributors 你可以注册实现了[`InfoContributor`](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/InfoContributor.java)接口的Spring beans来提供自定义应用信息。以下示例暴露一个只有单个值的`example`实体: ```java import java.util.Collections; import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoContributor; import org.springframework.stereotype.Component; @Component public class ExampleInfoContributor implements InfoContributor { @Override public void contribute(Info.Builder builder) { builder.withDetail("example", Collections.singletonMap("key", "value")); } } ``` 如果点击`info`端点,你应该可以看到包含以下实体的响应: ```json { "example": { "key" : "value" } } ```