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

Har*_*son 5 spring ehcache spring-boot spring-boot-actuator

我有一个正在运行的执行器和缓存的 Spring Boot 应用程序。当我打电话时

http://localhost:8080/actuator/caches/myCacheName
Run Code Online (Sandbox Code Playgroud)

我只得到一些关于目标、名称和cacheManager的基本信息。

但我想查看这个特定缓存的所有条目。

那么是否可以自定义此端点以提供更多信息?

Tho*_*olf 2

您可以通过扩展来自定义当前端点。这是一个使用 @EndpointWebExtension 注释来扩展标准信息执行器端点以提供更多功能的示例。

示例取自此处: 扩展执行器端点

这是关于扩展端点的 spring 官方文档: Spring 扩展端点

@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;
    }
}
Run Code Online (Sandbox Code Playgroud)