SpringBoot2.1.9RELEASE配置hystrix-dashboard

2.0以上的版本配置hystrix-dashboard和之前的有所区别

1.导入依赖

      
        org.springframework.boot
        spring-boot-starter-parent
        2.1.9.RELEASE
         
    

   
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix-dashboard
        

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 getServlet() {
        HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
        servletRegistrationBean.setServlet(hystrixMetricsStreamServlet);
        servletRegistrationBean.addUrlMappings("/hystrix.stream");
        servletRegistrationBean.setName("HystrixMetricsStreamServlet");
        return servletRegistrationBean;
    }
}

4.可以启动服务 访问接口了

SpringBoot2.1.9RELEASE配置hystrix-dashboard_第1张图片

5.访问时出现了n个ping 不要害怕 他在等待你访问接口 以便进行数据分析

SpringBoot2.1.9RELEASE配置hystrix-dashboard_第2张图片

6.访问接口后 就会出现 如下的内容 一个json数据 可以进入到可视化界面进行查看

SpringBoot2.1.9RELEASE配置hystrix-dashboard_第3张图片

7.可视化界面 http://localhost:1002/hystrix

SpringBoot2.1.9RELEASE配置hystrix-dashboard_第4张图片

 

再次刷新接口就会有不一样的效果产生

SpringBoot2.1.9RELEASE配置hystrix-dashboard_第5张图片

 

SpringBoot2.1.9RELEASE配置hystrix-dashboard_第6张图片

你可能感兴趣的:(SpringBoot)