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

}

显式指定路径参数名。

相关推荐
Drifter_yh3 分钟前
「JVM」 并发编程基石:Java 内存模型(JMM)与 Synchronized 锁升级原理
java·开发语言·jvm
Seven975 分钟前
CompletableFuture深度解析:异步编程与任务编排的实现
java
kyrie学java6 分钟前
SpringBoot搭建项目调试与问题解决
java·spring boot·后端
SimonKing9 分钟前
多数据源:CSV、内存对象可以通过SQL查询,甚至联查,你敢信!
java·后端·程序员
毕设源码-钟学长14 分钟前
【开题答辩全过程】以 高校疫情管理系统为例,包含答辩的问题和答案
java
cqbzcsq18 分钟前
MC Forge1.20.1 mod开发学习笔记(数据生成、食物)
java·笔记·学习·mc
Hx_Ma1622 分钟前
mybatis练习2
java·数据库·mybatis
山北雨夜漫步23 分钟前
MQ消息队列
java·开发语言
毕设源码-邱学长23 分钟前
【开题答辩全过程】以 基于Web的小型宾馆客房管理系统为例,包含答辩的问题和答案
java