标签:spring null com system obj 保护 read thread src
依赖:
<!--整合hystrix--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>
在要做容错处理的方法上加@HystrixCommand
注解,并指定一个容错方法,即fallbackMethod 。
/** * 进行容错处理 * fallbackMethod的方法参数个数类型要和原方法一致 * * @param id * @return */ @HystrixCommand(fallbackMethod = "queryItemByIdFallbackMethod") public Item queryItemById3(Long id) { String itemUrl = "http://app-item/item/{id}"; Item result = restTemplate.getForObject(itemUrl, Item.class, id); System.out.println("===========HystrixCommand queryItemById-线程池名称:" + Thread.currentThread().getName() + "订单系统调用商品服务,result:" + result); return result; } /** * 请求失败执行的方法 * fallbackMethod的方法参数个数类型要和原方法一致 * * @param id * @return */ public Item queryItemByIdFallbackMethod(Long id) { return new Item(id, "查询商品信息出错!", null, null, null); }
转载自:https://blog.csdn.net/hellozpc/article/details/83692496
标签:spring null com system obj 保护 read thread src
原文地址:https://www.cnblogs.com/linhongwenBlog/p/12518982.html