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

}

显式指定路径参数名。

相关推荐
Code季风15 分钟前
深度优化 spring 性能:从缓存、延迟加载到并发控制的实战指南
java·spring boot·后端·spring·缓存·性能优化
风象南22 分钟前
SpringBoot自定义RestTemplate的拦截器链
java·spring boot·后端
NCHUtianlin23 分钟前
JAVA生成PDF(itextpdf)
java·开发语言·pdf
yiridancan24 分钟前
终极剖析HashMap:数据结构、哈希冲突与解决方案全解
java·数据结构·算法·哈希算法
拼搏@2 小时前
第十六天,7月10日,八股
java·mybatis
白仑色4 小时前
Spring Cloud Gateway 实战指南
spring boot·微服务·路由转发·限流熔断
Sylvia-girl6 小时前
Java——抽象类
java·开发语言
Touper.9 小时前
Redis 基础详细介绍(Redis简单介绍,命令行客户端,Redis 命令,Java客户端)
java·数据库·redis
m0_535064609 小时前
C++模版编程:类模版与继承
java·jvm·c++
虾条_花吹雪10 小时前
Using Spring for Apache Pulsar:Message Production
java·ai·中间件