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
再次刷新接口就会有不一样的效果产生