解决访问Hystrix的/hystrix.stream端点返回404问题
错误界面
需要在Springboot项目启动类中,配置Bean设置如下 :
具体原因请查看springboot2.0下hystrix.stream 404
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
但此时可能会提示无法找到HystrixMetricsStreamServlet类;
Hystrix监控是使用Hystrix的hystrix-metrics-event-stream模块,就可以将这些监控的指标信息以text/event-stream的格式暴露给外部系统,所以需要引入hystrix-metrics-event-stream依赖
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-metrics-event-stream</artifactId>
</dependency>
在spring-cloud-starter-netflix-hystrix中已包含hystrix-metrics-event-stream模块,或者直接引入下面依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
问题解决!