PathVariable annotation was empty on param 0

错误显示:

使用SpringBoot进行开发时,使用feign组件进行远程调用,可能会产生了这样的异常信息:

 nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0

原因:
从异常信息中看出,是因为PathVariable注解有问题!也就是@PathVariable注解的第0个值为空!

当时声明明Feign接口方法时候,使用@PathVariable注解的接口方法:

@GetMapping("/account/{clientId}")
public User get(@PathVariable String clientId);

path路径部分只有一个clientId变量,那么说在“was empty on param 0”,也就是说clientId值没有取到!

解决:
将@PathVariable修改为@PathVariable(value="clientId")的写法,明确带有value="clientId"

@GetMapping("/account/{clientId}")
public User get(@PathVariable(value="clientId") String clientId);

一句话总结:

使用feign时,如果参数中带有@PathVariable则需要使用value显示指明参数名

posted @   寒冷的雨呢  阅读(1261)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示