1、Pom 文件(actuator、dashboard、javanica)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
</dependency>
2、Main启动类
@SpringBootApplication
@EnableHystrixDashboard
public class DashBoard {
public static void main(String[] args) {
SpringApplication.run(DashBoard.class,args);
}
// 此配置是为了服务监控而配置,与服务容错本身无关,
// ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
// 只要在自己的项目里配置上下面的servlet就可以了
@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;
}
}
3、启动服务,浏览器输入http://localhost:${port}/hystrix

地址栏填写: http://localhost:${port}/actuatr/hystrix.stream,这里port为服务提供者端口。
 此时出现404错误,检查服务提供者pom文件是否包含actuator依赖,并且application.yml文件是否打开端点  
management:
endpoints:
web:
exposure:
include: "*"
重启启动,运行,再次进入dashboard页面,如果一直显示Loading,可以先进入服务提供者的url,然后再进入dashboard。 
|