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

}

显式指定路径参数名。

相关推荐
888CC++9 分钟前
java 并发编程
java·开发语言·python
无风听海27 分钟前
JSON Web Token(JWT)完全指南
java·前端·json
JAVA社区1 小时前
Java高级全套教程(十一)—— Kubernetes 超详细企业级实战详解
java·运维·微服务·容器·面试·kubernetes
在繁华处2 小时前
Java从零到熟练(九):并发编程基础
java·开发语言
木头程序员3 小时前
SSM框架学习笔记
java·开发语言·mysql·spring·maven
李白你好3 小时前
页面资产梳理 · 技术指纹识别 · Spring 端点探测
java·后端·spring
一起逃去看海吧3 小时前
dify-03
java·linux·开发语言
我是一颗柠檬3 小时前
【Java后端技术亮点】热Key探测与本地缓存二级防护:Redis热点问题的终极解决方案
java·redis·后端·缓存·中间件
Refrain_zc4 小时前
Android 音视频通话核心 —— 音频编码(AAC)完整解析
java
xiaoshuaishuai84 小时前
C# AvaloniaUI 资源找不到报错
java·服务器·前端·windows·c#