1.引入依赖,如果依赖引入失败看我的另一篇博文,刚刚写的
<!--hytrix dashbord组件依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!--spring boot actuator依赖,需要用来配合dashbord-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在启动类添加注解开启Hytrix dashbord
@EnableHystrixDashboard //监视熔断器的依赖
现在可以正常访问“/hytrix”,但是“hytrix.stream”报404,这是因为使用的是spring boot 2.0及以上版本
解决:新建或者在已有的配置类加上
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
ok