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

}

显式指定路径参数名。

相关推荐
DolphinScheduler社区16 分钟前
Apache DolphinScheduler 与 Spring Cloud Data Flow:差异与优势解析
spring·spring cloud·apache·海豚调度·大数据工作流调度
极客先躯1 小时前
高级java每日一道面试题-2025年12月09日-实战篇[Docker]-如何配置 Docker 的日志驱动?有哪些日志驱动可选?
java·docker·日志驱动的作用与配置层级·日志驱动全览与对比·日志驱动配置的要点·日志标签定制·容器与宿主机时间戳
身如柳絮随风扬1 小时前
门户服务缓存架构优化:从分级缓存到双缓存,彻底解决毛刺现象与一致性问题
spring·缓存·架构
rabbit_pro1 小时前
Spring AI使用Ollama
java·人工智能·spring
Mike117.1 小时前
GBase 8a 物化视图依赖和 DDL 风险排查记录
java·服务器·前端
李少兄1 小时前
领域驱动设计与 Clean Code 的实践
java·数据库·领域驱动
老马95272 小时前
opencode7-桌面应用实战2
java·人工智能·后端
李白的天不白2 小时前
大规模请求数据并发问题
java·前端·数据库
霸道流氓气质2 小时前
SpringAI+Ollama本地模型实现快速对话入门实例
spring boot·ai