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

}

显式指定路径参数名。

相关推荐
:12131 分钟前
java继承
java·开发语言
それども36 分钟前
怎么理解 LEFT JOIN 和 LEFT SEMI JOIN
java·数据库·mysql
日月云棠1 小时前
JAVA数据结构与算法 - 基础:数组深度解析
java·后端
WL_Aurora1 小时前
Java多线程详解(二):线程池、同步机制与并发工具类
java·多线程·并发
Java技术小馆1 小时前
微信本地数据提取/接入AI神器
java
日月云棠1 小时前
JAVA数据结构与算法 - 基础:核心概念与框架总览
java·后端
Dicky-_-zhang1 小时前
分布式系统限流熔断实战:保护微服务稳定性
java·jvm
椰猫子2 小时前
SpringBoot(简介、基础配置、整合第三方技术)
java·spring boot·spring
努力成为AK大王2 小时前
Java并发线程核心知识(一)
java·开发语言·面试