前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.

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

作者头像
joshua317
发布2022-10-31 11:47:14
6750
发布2022-10-31 11:47:14
举报
文章被收录于专栏:技术博文

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/282

错误显示:

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

代码语言:javascript
复制
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxx': Injection of resource dependencies failed; 

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxx': Injection of resource dependencies failed;

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxx': FactoryBean threw exception on object creation; 

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

重点看这句话的异常信息

代码语言:javascript
复制
nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
代码语言:javascript
复制
原因:

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

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

代码语言:javascript
复制
@GetMapping("/account/{clientId}")
public User get(@PathVariable String clientId);

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

解决:

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

代码语言:javascript
复制
@GetMapping("/account/{clientId}")
public User get(@PathVariable(value="clientId") String clientId);

重新编译即可!

一句话总结:

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

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/282

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-10-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档