原来是这么写的
@Component
@FeignClient(value = "server-vod", fallback = VodFileDegradeFeignClient.class) //fallback出错之后执行的方法
@RequestMapping("/vod/video")
public interface VodClient {
//从阿里云删除视频
@DeleteMapping("/{videoId}")
public R deleteVideoAly(@PathVariable("videoId") String videoId);
//从阿里云删除多个视频
@DeleteMapping("/deleteVideoAlyByIds")
public R deleteVideoAlyByIds(@RequestBody List<String> videoIdList);
}
服务降级是这么写的
@Component
public class VodFileDegradeFeignClient implements VodClient {
// feign调用出错之后会执行
public R deleteVideoAly(String videoId) {
return R.error().message("删除视频出错");
}
public R deleteVideoAlyByIds(List<String> videoIdList) {
return R.error().message("删除多个视频出错");
}
}
然后就一直报错
![](https://i-blog.csdnimg.cn/blog_migrate/22b6064118d49199d6202205ef1b1849.png)
测试了多次,确定是url问题
正确的应该这么写
把feign调用url的类RequestMapping去掉即可,把url加到方法中
@Component
@FeignClient(value = "server-vod", fallback = VodFileDegradeFeignClient.class) //fallback出错之后执行的方法
public interface VodClient {
//从阿里云删除视频
@DeleteMapping("/vod/video/{videoId}")
public R deleteVideoAly(@PathVariable("videoId") String videoId);
//从阿里云删除多个视频
@DeleteMapping("/vod/video/deleteVideoAlyByIds")
public R deleteVideoAlyByIds(@RequestBody List<String> videoIdList);
}
启动成功
记个坑,要用服务降级就不要在类上设置RequestMapping了。
都加在方法中即可!!