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

}

显式指定路径参数名。

相关推荐
Kiyra13 分钟前
从上传到可问答:Interview Agent 的知识库 RAG 链路
java·人工智能·后端·spring·职场和发展
拙野17 分钟前
工作中Mybatis动态SQL的使用
java·sql·mybatis
AI人工智能+电脑小能手23 分钟前
【大白话说Java面试题】【Java基础篇】第39题:说说反射的用途及实现原理,Java获取反射(Class)的三种方法
java·开发语言·后端·python·面试
PeterLi28 分钟前
踩坑实录:JRebel 启动报 Mapper 重复 ID 异常,IDEA 普通启动却正常?
java·后端
小碗羊肉43 分钟前
【JavaWeb | 第五篇】JDBC
java·开发语言·数据库
江南十四行1 小时前
Python上下文管理器与with语句——资源管理的艺术
java·jvm·数据库
书源丶1 小时前
四十五、函数式接口与 Lambda 表达式
java·开发语言
直奔標竿1 小时前
MySQL与Redis数据一致性实战方案(避坑指南)
java·数据库·spring boot·redis·mysql·spring·缓存
java1234_小锋1 小时前
Java进程突然挂了如何排查?
java·开发语言
夕除1 小时前
spring boot--04
java·spring boot