转载请注明作者及出处:
作者:银河架构师
原文链接:https://blog.csdn.net/liuminglei1987/article/details/103891303
问题描述
在项目中集成断路器监控的时候,访问/actuator/htstrix.stream经常会遇到404问题,如下图所示:
此问题根本原因就在于此端点压根就没创建,所以,才会报404错误。
分析解决
如何排查呢?具体有以下几点:
actuator依赖
查确认否引入了spring-boot-starter-actuator依赖。另外,spring-boot-starter-actuator、spring-cloud-starter-netflix-hystrix、spring-cloud-starter-netflix-hystrix-dashboard三个依赖,缺一不可。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
@EnableHystrixDashboard注解
确认启动类是否引入了@EnableHystrixDashboard注解。
@EnableCircuitBreaker注解
确认启动类是否添加了@EnableCircuitBreaker注解。这个是忽略比较多的一项重要原因。
@EnableHystrix
如果项目基于ribbon,确认启动类是否添加了@EnableHystrix注解。
feign开启hystrix
feign.hystrix.enabled是否为true。需要注意的是,此参数不会影响端点创建,只会影响feign的熔断降级功能是否开启。
配置
确认management.endpoints.web.exposure.include包含的有hystrix.stream,或者直接为'*'。此项为最常见的原因,前面都检查过了,都没问题,那就100%是这个原因了。
management:
endpoints:
web:
exposure:
include: hystrix.stream
management:
endpoints:
web:
exposure:
include: '*'
最后,如果全部点均排除完毕,配置也正确,那么,启动项目之后,查看控制台,出现如下提示即算成功。
明确提示,注册hystrix.stream-actuator-endpoint端点/actuator/hystrix.stream成功。
刷新/actuator/hystrix.stream端点,已正常出现ping命名获取数据。
微信搜索【银河架构师】,发现更多精彩。