添加依赖

<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";
}
}

hystrix 给方法加断路器的更多相关文章

  1. js中settimeout方法加参数

    js中settimeout方法加参数的使用. 简单使用看w3school  里面没有参数调用,  例子: <script type="text/javascript"> ...

  2. 使用ajax()方法加载服务器数据

    使用ajax()方法加载服务器数据 使用ajax()方法是最底层.功能最强大的请求服务器数据的方法,它不仅可以获取服务器返回的数据,还能向服务器发送请求并传递数值,它的调用格式如下: jQuery.a ...

  3. Java中主类中定义方法加static和不加static的区别

     Java中主类中定义方法加static和不加static的区别(前者可以省略类名直接在主方法调用(类名.方法),后者必须先实例化后用实例调用) 知识点:1.Getter and Setter 的应用 ...

  4. 使用Application.GetResourceStream方法加载资源时得到的总是null

    我们可以预先把程序中用到的资源,如图片,音乐等放入项目中,打包进XAP文档,需要的时候从中调用.下面就说说具体实现方法. 第一步,把数据存进项目. 1.右键点击项目名称-添加-新建文件夹(英文版请自行 ...

  5. 使用AddLayer方法加载shp文件中使用的Map、Dataset等对象详解

    内容源自:ArcGIS Engine+C#入门经典 方法二:使用axMapControl1对象的AddLayer方法加载ShapeFile文件 添加ShapeFile文件需要用到Map.Dataset ...

  6. MFC使用LoadBitmap方法加载位图文件失败解决方案(转)

    用如下方法在原项目中使用LoadBitmap方法加载已有的位图资源作为背景没有问题,但放在别的项目中总是加载不出来,该函数返回NULL HBITMAP hBitmap=LoadBitmap((HINS ...

  7. jQuery使用load方法加载其他文档内容

    A文档载入B文档的内容,并且通过JQ操作被引入到A文档中的元素 A文档 (index.html): <!DOCTYPE html> <html lang="en" ...

  8. Xcode 7 ImageNamed 方法加载jpg图片失败

    更新XCode7后 原来的Image.xcassets文件夹变成了Assets.xcassets 把01.jpg,02.jpg,03.png拖入这个文件夹中 UIImage* test1=[UIIma ...

  9. 如何在Eclipse中给main方法加参数

    在main方法中有一个args参数,那么如何给args参数赋值呢? public class TestMain { public static void main(String[] args) { f ...

随机推荐

  1. Mycat概述

    Mycat是什么?从定义和分类来看,它是一个开源的分布式数据库系统,是一个实现了MySQL协议的的Server,前端用户可以把它看作是一个数据库代理,用MySQL客户端工具和命令行访问,而其后端可以用 ...

  2. plsql developer点滴

    PLSql中查看编译错误的具体内容: 1. 打开Command Windows show errors procedure procedure_name 

  3. AtCoder Grand Contest 009 E:Eternal Average

    题目传送门:https://agc009.contest.atcoder.jp/tasks/agc009_e 题目翻译 纸上写了\(N\)个\(1\)和\(M\)个\(0\),你每次可以选择\(k\) ...

  4. AtCoder Regular Contest 074 E:RGB Sequence

    题目传送门:https://arc074.contest.atcoder.jp/tasks/arc074_c 题目翻译 给你一行\(n\)个格子,你需要给每个格子填红绿蓝三色之一,并且同时满足\(m\ ...

  5. RDA项目打包

    注意APP的编译搭建: ./aps/Makefile.toolchain //ccoption path的设定 ./aps/rules.mak //统一的编译规则 MAKE -C 1.TOOLS的可执 ...

  6. 三 lambda表达式有什么用

    (转载: https://mp.weixin.qq.com/s/-PHOc6p-qKJBktle28AUgA) 一: 直接把代码块赋值给变量 我们知道,对于一个Java变量,我们可以赋给其一个“值”. ...

  7. 条款29:为“异常安全”而努力是值得的

    当异常被抛出时,带有异常安全性的函数: 1.不泄露任何资源 2.不允许数据败坏   异常安全函数提供以下三个保证之一: 1.基本承诺:如果异常被抛出,程序内的任何事物仍然保持在有效的状态下.没有任何对 ...

  8. asn编译常见报错

    TypeError: unsupported operand type(s) for -: 'str' and 'int' 可能是该用列表的地方没用列表. 1. ’-‘不支持,需改为'_' asn1t ...

  9. Beetl使用注意事项

    1.如果表达式跟定界符或者占位符有冲突,可以在用 “\” 符号 @for(user in users){ email is ${user.name}\@163.com @} ${[1,2,3]} // ...

  10. Jinkins定时任务设置

    设置的地方在构建触发器中 Build after other projects are built:在其他项目构建完成后再进行构建. Build periodically:周期进行构建 Build w ...