Spring Boot Actuator:自定义端点

要在Spring Boot Actuator中实现自定义端点,可以按照以下步骤进行操作:

1.创建一个自定义端点类

该类需要使用`@Endpoint`注解进行标记,并使用`@Component`注解将其作为Spring Bean进行管理。

package com.example.highactuator.point;

import lombok.extern.apachecommons.CommonsLog;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

@Component
@Endpoint(id = "customEndpoint")
public class CustomEndpoint {
    @ReadOperation
    public String customEndpoint() {
        return "Custom endpoint response";
    }
}

在上述示例中,我们创建了一个自定义端点类`CustomEndpoint`,并使用`@Endpoint`注解指定了端点的ID为`customEndpoint`。`@ReadOperation`注解用于标识该方法处理读取操作的请求。在本例中,该方法返回一个自定义的响应字符串。

2. 在application.yml`中配置端点的暴露路径和敏感性。

主要是下方图片中圈中的配置,其他内容忽略一下

management:
  endpoint:
    customEndpoint:
      sensitive: false #标记为非敏感
    health:
      show-components: when_authorized
  endpoints:
    web:
      base-path: /high
      path-mapping:
         health: heal
      exposure:
        include: health,customEndpoint #暴露路径

 上述配置指定了只暴露`customEndpoint`端点,并将其设置为非敏感。

3. 启动应用程序

可以通过`/actuator/customEndpoint`路径访问自定义端点。

通过以上步骤,你可以创建和暴露自定义的端点,并在访问对应的路径时获取自定义的响应。请根据实际需求来实现自定义端点的方法和逻辑,在方法中返回所需的监控数据或其他自定义操作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值