springcloud 第四篇:断路器(Hystrix)错误集锦

版权声明:本文为博主原创文章,未经博主允许转载将负法律责任。 https://blog.csdn.net/ningmengbaby/article/details/82712350

【前言】

最近在看方志朋的博客,敲到了第四章,遇到了一些错误分享给大家。

【过程】

注意:springboot版本为2.0.4

一、在ribbon使用断路器 

在pom.xml文件中加入spring-cloud-starter-hystrix的起步依赖之后,@HystrixCommand注解不可以用,解决方法

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency

二、Hystrix Dashboard(断路器:Hystrix仪表盘)

在pom.xml文件中加入仪表盘的起步依赖,@EnableHystrixDashboard注解不能用,解决方法

<dependency>
	<groupId> org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

打开浏览器:访问http:localhost:8764/hystrix  在文本框中输入 http://localhost:8764/hystrix.stream Title随意填写

点击monitor stream,进入下一个界面,访问:http://localhost:8764/hi?name=forezp

点击monitor stream 此时出现 unable to connection to Command Metric Stream 解决方法

在Application类中添加如下代码

@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;
  }

猜你喜欢

转载自blog.csdn.net/ningmengbaby/article/details/82712350