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

}

显式指定路径参数名。

相关推荐
房开民8 小时前
c++总结
java·开发语言·c++
好大哥呀8 小时前
C++ 多态
java·jvm·c++
毕设源码-赖学姐8 小时前
【开题答辩全过程】以 基于Java的医院器材管理系统的设计与实现为例,包含答辩的问题和答案
java·开发语言
float_com8 小时前
【java常用API】----- Arrays
java·开发语言
皮皮林5519 小时前
用 SpringBoot + Tess4j 优雅实现图像文字识别,真香!
spring boot
LuckyTHP10 小时前
迁移shibboleth java获取shibboleth用户信息
java·开发语言
客卿12310 小时前
数论===质数统计(暴力法,)
java·开发语言
华科易迅10 小时前
Spring 事务(注解)
java·数据库·spring
写代码的小阿帆10 小时前
Web工程结构解析:从MVC分层到DDD领域驱动
java·架构·mvc
东离与糖宝10 小时前
Java 26+Spring Boot 3.5,微服务启动从3秒压到0.8秒
java·人工智能