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