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

}

显式指定路径参数名。

相关推荐
C_V_Better4 分钟前
Spring Security 如何防止 CSRF 攻击?
java·开发语言·数据结构·后端·算法·spring·csrf
customer081 小时前
【开源免费】基于SpringBoot+Vue.JS酒店管理系统(JAVA毕业设计)
java·vue.js·spring boot·后端·spring cloud·开源
充满诗意的联盟1 小时前
DDD该怎么去落地实现(4)多对多关系
java·开发语言
m0_748234711 小时前
Spring Boot 集成 Kafka
spring boot·kafka·linq
快乐非自愿1 小时前
Java中使用FFmpeg拉取RTSP流
java·开发语言·ffmpeg
Code额1 小时前
SpringBoot 中的 Redis 序列化
spring boot·redis
天天向上杰1 小时前
地基简识Spring MVC 组件
java·spring·mvc·springmvc
武昌库里写JAVA1 小时前
【Redis学习】Redis Docker安装,自定义config文件(包括RDB\AOF setup)以及与Spring Boot项目集成
java·开发语言·spring boot·学习·课程设计
是一只派大鑫2 小时前
从头开始学SpringMVC—02获取请求参数&向域对象共享数据
java·后端·springmvc
大丈夫在世当日食一鲲2 小时前
1JVM概念
java