nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/282
错误显示:
使用SpringBoot进行开发时,使用feign组件进行远程调用,可能会产生了这样的异常信息:
1 2 3 4 5 6 7 | 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 . |
重点看这句话的异常信息
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显示指明参数名
本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/282
分类:
Java
, Springboot
标签:
Java
, SpringBoot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
2021-10-21 一天一个 Linux 命令(31):mount 命令
2021-10-21 Java基础(4)-Java标识符和关键字
2021-10-21 Java打印九九乘法表