1、依赖包
<!-- 熔断相关依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-hystrix</artifactId> <version>2.2.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-commons</artifactId> <version>2.2.9.RELEASE</version> </dependency>
2、启动application启动类增加注解
@EnableHystrix@EnableCircuitBreaker
3、被调用方法上增加注意
@HystrixCommand(commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")}, fallbackMethod = "getCouponFallback")其他fallbackMethod为熔断时执行的方法