2.0以上的版本配置hystrix-dashboard和之前的有所差別
1.導入依賴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<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>
2.修改啟動類
@EnableEurekaClient
@SpringBootApplication
@EnableHystrixDashboard
public class SemaPhoreApplicationBreaker {
public static void main(String[] args) {
SpringApplication.run(SemaPhoreApplicationBreaker.class, args);
}
}
3.增加一個配置類 否則通路儀表盤時404
package com.fpy.config;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
@org.springframework.context.annotation.Configuration
public class Configuration {
@Bean
public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean<HystrixMetricsStreamServlet> servletRegistrationBean = new ServletRegistrationBean();
servletRegistrationBean.setServlet(hystrixMetricsStreamServlet);
servletRegistrationBean.addUrlMappings("/hystrix.stream");
servletRegistrationBean.setName("HystrixMetricsStreamServlet");
return servletRegistrationBean;
}
}
4.可以啟動服務 通路接口了
5.通路時出現了n個ping 不要害怕 他在等待你通路接口 以便進行資料分析
6.通路接口後 就會出現 如下的内容 一個json資料 可以進入到可視化界面進行檢視
7.可視化界面 http://localhost:1002/hystrix
再次重新整理接口就會有不一樣的效果産生