解决Hystrix:Dashboard监控流显示ping没有内容
1、问题图片
2、解决办法
1、看看请求的路径对不对
确保请求的路径能够访问
2、加上熔断机制
在controller层
@RequestMapping("/dept/get/{id}")
@HystrixCommand(fallbackMethod = "hystrixGet")
public Dept queryById(@PathVariable("id") Long id){
Dept dept=service.queryById(id);
if (dept==null){
throw new RuntimeException("id=>"+id+",不存在该用户,或信息没有找到");
}
return dept;
}
//备选方案
public Dept hystrixGet(@PathVariable("id") Long id){
return new Dept()
.setDept_no(id)
.setDept_name("id=>"+id+"没有对应的信息,@hystrix")
.setDb_source("no this database in mysql");
}
在启动类上
@SpringBootApplication
@EnableEurekaClient //在服务启动后服务自动注册到Eureka
@EnableDiscoveryClient // 服务发现
@EnableCircuitBreaker //添加对熔断的支持
public class Dept_8001 {
public static void main(String[] args) {
SpringApplication.run(Dept_8001.class,args);
}
//增加一个servlet
@Bean
public ServletRegistrationBean hystrixMetricsStreamServlet(){
ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
registrationBean.addUrlMappings("/actuator/hystrix.stream");
return registrationBean;
}
}