通过Spring Boots Actuator Endpoint / caches显示缓存条目

时间:2019-05-29 13:42:21

标签: spring spring-boot ehcache spring-boot-actuator

我有一个运行Actuator和Caching的Spring Boot应用程序。 当我打电话

http://localhost:8080/actuator/caches/myCacheName

我仅获得有关目标,名称和cacheManager的一些基本信息。

但是我想查看此特定缓存的所有条目。

那么可以自定义该端点以向我提供更多信息吗?

1 个答案:

答案 0 :(得分:0)

您可以通过扩展它们来自定义当前端点。这是一个使用@EndpointWebExtension批注扩展标准信息执行器终结点功能的示例。

示例取自此处: Extend actuator endpoints

这是关于扩展端点的springs官方文档: Spring extending endpoints

@Component
@EndpointWebExtension(endpoint = InfoEndpoint.class)
public class InfoWebEndpointExtension {

    private InfoEndpoint delegate;

    // standard constructor

    @ReadOperation
    public WebEndpointResponse<Map> info() {
        Map<String, Object> info = this.delegate.info();
        Integer status = getStatus(info);
        return new WebEndpointResponse<>(info, status);
    }

    private Integer getStatus(Map<String, Object> info) {
        // return 5xx if this is a snapshot
        return 200;
    }
}
相关问题