因为使用的是注解方式,所以我们需要设置Aspect
- 依赖(hystrix-core至少要1.5.9以上)
1 | <dependency> |
- 启动类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
@Bean
public ServletRegistrationBean servletRegistrationBean() {
// ServletName默认值为首字母小写,即myServlet
return new ServletRegistrationBean(new HystrixMetricsStreamServlet(), "/hystrix.stream");
}
// 向Spring容器注入HystrixCommandAspect
@Bean(name = "hystrixAspect")
public HystrixCommandAspect hystrixCommandAspect() {
return new HystrixCommandAspect();
}
} - 控制器
1 | @Controller |