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

}

显式指定路径参数名。

相关推荐
Pluchon4 分钟前
硅基计划4.0 算法 记忆化搜索
java·数据结构·算法·leetcode·决策树·深度优先
大飞哥~BigFei5 分钟前
deploy发布项目到国外中央仓库报如下错误Project name is missing
java
白羊无名小猪5 分钟前
正则表达式(捕获组)
java·mysql·正则表达式
狂奔小菜鸡7 分钟前
Day23 | Java泛型详解
java·后端·java ee
onejson7 分钟前
idea中一键执行maven和应用重启
java·maven·intellij-idea
CoderYanger7 分钟前
动态规划算法-简单多状态dp问题:13.删除并获得点数
java·开发语言·数据结构·算法·leetcode·动态规划·1024程序员节
听风吟丶9 分钟前
Java 微服务 APM 实战:Prometheus+Grafana 构建全维度性能监控与资源预警体系
java·微服务·prometheus
ohnoooo911 分钟前
C++ STL库常用容器函数
java·开发语言
天骄t14 分钟前
深入解析栈:数据结构与系统栈
java·开发语言·数据结构
CoderYanger16 分钟前
A.每日一题——3625. 统计梯形的数目 II
java·算法·leetcode·职场和发展