springcloud 第四篇:断路器(Hystrix)错误集锦 妖狐艹你老母 2022-05-12 06:28 142阅读 0赞 【前言】 最近在看方志朋的博客,敲到了第四章,遇到了一些错误分享给大家。 【过程】 > 注意: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; }
还没有评论,来说两句吧...