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

}

显式指定路径参数名。

相关推荐
PythonFun9 分钟前
WPS动态序号填充,告别手动调整烦恼
java·前端·python
Hx_Ma1610 分钟前
测试题(二)
java·开发语言
利刃大大19 分钟前
【SpringCloud】远程调用OpenFeign && 快速入手 && 参数传递 && 继承方式 && 抽取方式 && 远程部署
后端·spring·spring cloud·openfeign·远程调用
2501_9369603620 分钟前
ROS快速入门杰哥教程1-77残缺版
java·开发语言
小灵吖23 分钟前
LangChain4j 记忆化(ChatMemory)
java·后端
用户10859329934124 分钟前
Java集合框架完全指南
java
冬夜戏雪24 分钟前
Leetcode 颠倒二进制位/二进制求和
java·数据结构·算法
Never_Satisfied38 分钟前
在c#中,获取文件的大小
java·开发语言·c#
蜂蜜黄油呀土豆40 分钟前
浅拷贝与深拷贝:实现与应用解析
java·浅拷贝·深拷贝·对象复制
014-code43 分钟前
Spring Boot 集成 Neo4j 图数据库实战教程
java·数据库·neo4j