SpringBoot项目启动报错:PathVariable annotation was empty on param 0.

报错信息

SpringBoot项目启动报错:Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.obstetric.archive.feignclient.DictServiceClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.

参数传递错误,没有找到参数。

错误代码
java 复制代码
@FeignClient(name = "dict", url = "http://localhost:8184/dict",
        fallbackFactory = DictServiceClientFallbackFactory.class)
public interface DictServiceClient {

    @PostMapping("/obstetric/{type}/{label}")
    Integer getValueByTypeAndLabel(@PathVariable String type, @PathVariable String label);

}

在普通的Controller中可以省略路径参数名,但项目中使用了Feign的远程调用,在注解@PathVariable中若不显示指明参数名,就会报错。

修改代码
java 复制代码
@FeignClient(name = "dict", url = "http://localhost:8184/dict",
        fallbackFactory = DictServiceClientFallbackFactory.class)
public interface DictServiceClient {

    @PostMapping("/obstetric/{type}/{label}")
    Integer getValueByTypeAndLabel(@PathVariable("type") String type, @PathVariable("label") String label);

}

显式指定路径参数名。

相关推荐
JMchen12317 小时前
Android后台服务与网络保活:WorkManager的实战应用
android·java·网络·kotlin·php·android-studio
阔皮大师17 小时前
INote轻量文本编辑器
java·javascript·python·c#
小法师爱分享17 小时前
StickyNotes,简单便签超实用
java·python
qq_2975746717 小时前
Linux 服务器 Java 开发环境搭建保姆级教程
java·linux·服务器
金牌归来发现妻女流落街头17 小时前
【从SpringBoot到SpringCloud】
java·spring boot·spring cloud
毅炼17 小时前
Java 基础常见问题总结(4)
java·后端
张3蜂17 小时前
深入理解 Python 的 frozenset:为什么要有“不可变集合”?
前端·python·spring
GR23423417 小时前
2025年影视仓TV+手机官方版 内置地址源支持高清直播
java·智能手机·软件
皮卡丘不断更17 小时前
手搓本地 RAG:我用 Python 和 Spring Boot 给 AI 装上了“实时代码监控”
人工智能·spring boot·python·ai编程
程序员清风18 小时前
北京回长沙了,简单谈谈感受!
java·后端·面试