spring boot2.x之后不提供hystrix.stream节点处理方法
作为springBoot2.x以后不在提供hystrix.stream节点,导致hystrix数据监控无法返回数据,从而使返回的页面为404,在这里有两种解决方法。
1、在被监控的服务启动类中或者添加一个配置类,来添加hystrix.stream节点
注意:此配置的访问地址为:
http://服务ip地址:端口/hystrix.stream
(1)添加配置类
@Configuration
public class ConfigBean {
@Bean
public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean<HystrixMetricsStreamServlet> bean = new ServletRegistrationBean<>(servlet);
bean.addUrlMappings("/hystrix.stream");
bean.setName("HystrixMetricsStreamServlet");
return bean;
}
}
(2)在启动类中添加以下代码,添加hystrix.stream节点
@SpringBootApplication
@EnableZuulProxy //开启网关服务zuul
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
@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;
}
}
2、在被监控的服务中的全局配置文件中,添加hystrix.stream节点
注意:此配置的访问地址为:
http://服务ip地址:端口/actuator/hystrix.stream
在全局配置文件在加入以下配置:
#暴露shutdown,hystrix.stream端点服务
management.endpoints.web.exposure.include=shutdown,hystrix.stream