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);

}

显式指定路径参数名。

相关推荐
Pniubi5 小时前
HashMap的扩容和树化边界
java·开发语言
Mikko75 小时前
用 Java 复刻了高中时在塞班上玩的「熔岩矿车」:纯 Swing、零依赖、没有一张图片,一个 jar 双击就能玩
java·游戏开发·swing
知了学历孙老师5 小时前
小自考的校考和统考,出题方和难度差在哪
java·大数据·前端
Java爱好狂.6 小时前
Java初学者如何一周速通SpringBoot!
java·spring boot·后端·spring·高并发·架构师·java面试
秋饼6 小时前
LLM API密钥动态轮换实战:Spring Vault + Spring AI + 多Provider路由
java·ai·技术分享·后端开发
福兮说8 小时前
JSON 格式正确,数据就可靠吗?我用一份自编配置检查类型与空值
java·前端·json
紧跟先前的步伐9 小时前
Go AI Agent 实战 03|Token、上下文窗口与模型调用成本
java·人工智能·golang
const_qiu10 小时前
第四章 00:开篇 —— 从「会聊天」到「记得住、会干活、能协作」
java·开发语言·人工智能·python
Wang's Blog10 小时前
Java 项目实战: 交友项目 - 个人资料管理的更新接口实现与坑
java·开发语言·交友
Promising_GEO10 小时前
GEE实战02期:从卫星波段开始:利用 Sentinel-2 自己计算 NDVI
java·sentinel·遥感·空间分析