情況描述
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;
}