還是在學(xué)習(xí)hystrix監(jiān)控的時候遇到了一個問題,訪問過http://localhost:7913/hystrix.stream之后就顯示Unable to connect to Command Metric Stream。這是為什么呢?
我就查了一下資料,前輩說springBoot1.5是可以的,那為什么2.0就不行了呢?
進(jìn)入源代碼中查看一下,發(fā)現(xiàn)spring2.0的一個Servlect被注釋掉了,我們只要在自己的項目里配置上這個servlet就ok了。
具體操作:
@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;
}
這樣就可以了。