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

}

显式指定路径参数名。

相关推荐
kuntli1 分钟前
Spring Bean生命周期全解析
java
ok_hahaha2 分钟前
java从头开始-苍穹外卖-day06-微信小程序开发-微信登录和商品浏览
java·微信·微信小程序·小程序
Java面试题总结10 分钟前
Spring @Validated失效?原因、排查与高效解决方案全解析
java·spring boot·spring
剑锋所指,所向披靡!30 分钟前
MySQL数据的增删改查
java·数据库·mysql
Villiam_AY34 分钟前
一次 DNS 端口引发的代理网络和公司内网冲突问题
java·服务器·数据库
dgvri41 分钟前
比较Spring AOP和AspectJ
java
eggwyw44 分钟前
springboot和springframework版本依赖关系
java·spring boot·后端
韩立学长1 小时前
Springboot奶茶加盟信息管理系统m307m786(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
开longlong了吗?1 小时前
Luan Takeaway——大模型驱动的智能外卖管理系统( Spring Cloud、Langchain4j )
后端·spring·spring cloud·langchain
于先生吖2 小时前
国际版JAVA婚恋交友系统源码:多语言适配,可商用的跨境婚恋解决方案
java·大数据·交友