添加依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>

1.启动类

@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan("Cloud_Hystrix.*")
@EnableCircuitBreaker
public class HystrixController {
public static void main(String[] args) {
SpringApplication.run(HystrixController.class, args);
}
}

2,controller

@RestController
@RequestMapping(value="/reqmap",produces={"application/json;charaset=utf-8"},method=RequestMethod.GET)
public class HystrixReqMap {
@Autowired
HystrixService hystrixService;
@RequestMapping("")
public String reqmap(String param){
return hystrixService.reqmap(param);
}
}

3.service

@Service
public class HystrixService {
@HystrixCommand(fallbackMethod="fail")
public String reqmap(String param){
if(param.equals("aaa")){
throw new RuntimeException();
}
return param+"--hystrix";
}
public String fail(String param){
return "runtimeException";
}
}

最新文章

  1. 阮一峰对js的见解(10大缺陷)
  2. JS围棋半成品
  3. AP创建会计科目
  4. 细说new与malloc的10点区别
  5. 2016HUAS_ACM暑假集训2G - Who&#39;s in the Middle
  6. robots.txt协议-互联网robots搜索规范
  7. @深入注解,在Java中设计和使用自己的注解
  8. opencv源代码
  9. hdoj1874 (优先队列+Dijkstra)
  10. Ubuntu12.04中安装ns-allinone-2.34
  11. Saruman&#39;s Army (POJ 3069)
  12. Html 笔记1
  13. Linux下ping,telnet,ssh命令的比较
  14. JVMGC机制
  15. MonkeyRunner测试工具小结
  16. 8大排序之Python实现 冒泡排序优化
  17. nodejieba中文分词
  18. [zz]有哪些优秀的科学网站和科研软件推荐给研究生?
  19. 原生js返回顶部(匀速、由快到慢)
  20. matlib实现logistic回归算法(序一)

热门文章

  1. python快速上手教程
  2. 【转】android adb常用指令
  3. 【转】eclipse修改workspace
  4. IIS7启用GZip压缩
  5. 黑科技抢先尝(续) - Windows terminal中WSL Linux 终端的极简美化指南
  6. Kth Largest Element in a Stream
  7. js混杂笔记
  8. Java基础--常用API--日期相关API
  9. form常用表单标签
  10. CCPC吉林站