情况描述
feign项目添加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-dashboard</artifactId>
</dependency>
运行项目出现Unable to connect to Command Metric Stream错误
原因
springboot 版本如果是2.0以上的dashboard的访问默认路径不是 “/hystrix.stream”,这就需要自己添加访问配置,修改访问路径,
只要在自己的项目里配置上下面的servlet就可以了
在启动类添加如下方法
添加访问路径
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}