当前位置: 代码网 > 服务器>服务器>Linux > SpringBoot如何拦截所有HealthIndicator的健康检查?

SpringBoot如何拦截所有HealthIndicator的健康检查?

2025年03月30日 Linux 我要评论
springboot拦截所有healthindicator健康检查方法为避免健康检查失败导致kubernetes服务重启,开发者需要拦截所有healthindicator调用并记录失败组件。由于hea

springboot如何拦截所有healthindicator的健康检查?

springboot拦截所有healthindicator健康检查方法

为避免健康检查失败导致kubernetes服务重启,开发者需要拦截所有healthindicator调用并记录失败组件。由于healthindicator的实现方式,基于执行的切点无法拦截所有调用。

解决方法是使用基于@annotation的切点:

@around("@annotation(org.springframework.boot.actuate.health.healthindicator)")
public object healthindicatoradvice(proceedingjoinpoint pjp) throws throwable {
    // 在此处记录失败的healthindicator实现
    object result = pjp.proceed();
    // 在此处进一步处理result
    return result;
}
登录后复制

此方法可拦截所有标注了@healthindicator注解的healthindicator实现的health()方法。

以上就是springboot如何拦截所有healthindicator的健康检查?的详细内容,更多请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com