1. 程式人生 > >Hystrix dashboard - Unable to connect to Command Metric Stream.

Hystrix dashboard - Unable to connect to Command Metric Stream.

 

 

在使用boot 2.0.*以上版本 + cloud Finchley.RELEASE

檢視儀表盤的時候會報錯

Unable to connect to Command Metric Stream

           <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import
</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.2.RELEASE</version> <type>pom</type> <scope>import
</scope> </dependency>

 

 

 

解決方案:

  
在專案中新增配置注意紅色部分

package com.amber.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration public class HystrixConfig { @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; } }                                                                                                     

 

 

然後就成功了