Spring Cloud Feign踩坑记录(二)

注意,以下的Feign遇到的坑,在高版本中有些已经修复。
某些项目由于历史包袱原因,无法进行全面升级,才需要修补这些坑。

1.启动报错:not annotated with HTTP method type (ex. GET, POST)
错误原因:
低版本的Feign不支持@PostMapping
解决方法:
在Feign中使用@RequestMapping,如下示:

@FeignClient(value = "base")
public interface OrderDetailService {

    @RequestMapping(value="/order/detail",method=RequestMethod.POST)
    JSONObject getOrderDetailByCdkey(@RequestParam("cdkey") String cdkey);

}

2.启动报错:RequestParam.value() was empty on parameter 0
错误原因:@RequestParam()注解内的参数不能为空
解决方法:加入具体参数,如@RequestParam("cdkey") String cdkey

3.启动报错:PathVariable annotation was empty on param 0.
错误原因:@PathVariable()注解内的参数不能为空
解决方法:加入具体参数,如@PathVariable("id") String id
示例如下:

@RequestMapping(value="/eureka/apps/{serviceName}", method=RequestMethod.GET)
public String getServiceInfoByserviceName(@PathVariable("serviceName") String serviceName) ;

}

相关博客:
SpringCloud Feign 踩到的坑(一)
参考资料:
https://blog.csdn.net/huaseven0527/article/details/80533983
https://blog.csdn.net/uotail/article/details/84673347

原文地址:https://www.cnblogs.com/expiator/p/10823604.html