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

}

显式指定路径参数名。

相关推荐
0xDevNull3 分钟前
Spring Boot 2.0动态多数据源切换实战教程
java·后端
语戚6 分钟前
力扣 2463. 最小移动总距离 —— 动态规划 & 贪心排序全解(Java 实现)
java·算法·leetcode·贪心算法·动态规划·力扣·dp
techdashen11 分钟前
Go 1.25 新特性:Flight Recorder —— 像黑匣子一样捕捉线上 Bug
java·golang·bug
妃衣11 分钟前
Html转word追加篇,关于hr标签分割线的显示
java·html·word
A_QXBlms12 分钟前
企微群发消息技术实现:定时任务+模板消息
java·mybatis·企业微信
小李子呢021115 分钟前
前端八股---axios封装
java·前端·javascript
斌味代码16 分钟前
SpringBoot 实战总结:踩坑与解决方案全记录
java·spring boot·后端
摇滚侠20 分钟前
Groovy 中如何定义集合
java·开发语言·python
0xDevNull24 分钟前
Spring Boot 3.0动态多数据源切换实战教程
java·spring boot·后端
代码漫谈25 分钟前
微服务 vs 单体架构:架构选型、实战拆解与决策指南
java·微服务·springboot·springcloud