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

}

显式指定路径参数名。

相关推荐
郑州光合科技余经理12 分钟前
实战:攻克海外版同城生活服务平台开发五大挑战
java·开发语言·javascript·数据库·git·php·生活
蟹至之13 分钟前
【MySQL】JDBC的使用(万字解析)
java·数据库·mysql·jdbc
爱笑的眼睛1114 分钟前
超越翻转与裁剪:面向生产级AI的数据增强深度实践与多模态演进
java·人工智能·python·ai
长孙阮柯15 分钟前
Java进阶篇(五)
java·开发语言
小张快跑。29 分钟前
Maven指定版本下载以及相关配置
java·maven
zhishidi31 分钟前
Spring @Scheduled注解调度机制详解
java·python·spring
⑩-31 分钟前
Blocked与Wati的区别
java·开发语言
AAA简单玩转程序设计34 分钟前
救命!Java这3个小技巧,写起来爽到飞起✨
java
IManiy40 分钟前
Java表达式引擎技术选型分析(SpEL、QLExpress)
java·开发语言
历程里程碑1 小时前
C++ 17异常处理:高效捕获与精准修复
java·c语言·开发语言·jvm·c++