您好,登錄后才能下訂單哦!
1、新增UserFeignClientFallbackFactory類,該類實現了FallbackFactory接口,重寫create接口:
@Component public class UserFeignClientFallackFactory implements FallbackFactory<UserFeignClient> { private static final Logger LOGGER = LoggerFactory.getLogger(UserFeignClientFallackFactory.class); @Override public UserFeignClient create(Throwable throwable) { return new UserFeignClient() { @Override public Map findById(Integer userId) { UserFeignClientFallackFactory.LOGGER.info("===================fallback;reason was:",throwable); Map<String, String> user = new HashMap<>(3); user.put("name","默認用戶"); user.put("id","-1"); user.put("age","18"); return user; } }; } }
2、修改FeignClient類:
@FeignClient(name = "user",fallbackFactory = UserFeignClientFallackFactory.class) public interface UserFeignClient { @RequestMapping(value = "/user/getUserInfo", method = RequestMethod.GET) Map findById(@RequestParam("userId") Integer userId); }
使用@FeignClient的fallbackFactory屬性設置回退邏輯。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。