赞
踩
1、创建一个fallbackfactory(捕获异常)类
- /**
- * FallbackFactory<T>:FeignTest1Service就是用于feign请求的接口
- * Created by py
- * 2020/3/26
- */
- @Component
- public class FeignTest1ServiceFallBackFactory implements FallbackFactory<FeignTest1Service> {
- @Override
- public FeignTest1Service create(Throwable throwable) {
- return new FeignTest1Service() {
- @Override
- public String testFeign(Map<String, String> map) {
- return "熔断了:{"+map.toString()+"},throwable:{"+throwable+"}";
- }
- };
- }
- }
2、feign调用接口配置fallback捕获异常参数
- /**
- * 此处使用的参数是fallbackFactory,不再是fallback
- **/
- @FeignClient(name = "test1",path ="eureka-clinet1",fallbackFactory = FeignTest1ServiceFallBackFactory.class,configuration = FeignAuthConfiguration.class)
- public interface FeignTest1Service {
-
- @RequestMapping(value = "/ribbonTest",method = RequestMethod.POST)
- public String testFeign(@RequestBody Map<String,String> map);
- }
3、请求接口
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。