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

}

显式指定路径参数名。

相关推荐
我是小妖怪,潇洒又自在几秒前
springcloud alibaba(八)链路追踪
后端·spring·spring cloud·sleuth·zipkin
深紫色的三北六号17 分钟前
大疆不同任务类型执行逻辑,上云API源码分析
java·无人机·springboot·大疆·上云api
BD_Marathon18 分钟前
【JavaWeb】IDEA运行并部署JavaWeb项目原理
java·ide·intellij-idea
7ioik20 分钟前
什么是类加载机制?
java
洛阳泰山20 分钟前
Java实现周易六爻自动排盘:根据起卦的公历时间换算农和干支时间,推算日柱空亡(旬空)
java·开发语言·周易·六爻·算卦
一只游鱼21 分钟前
我的第一个微服务项目cy-fang1.0
java·后端·spring cloud
缘来是庄24 分钟前
invalid comparison
java·spring boot·mybatis
哈哈哈笑什么38 分钟前
3 次生产系统崩溃复盘:Java 后端从踩坑到封神的排查优化之路
java·后端·性能优化
用户37215742613539 分钟前
如何在 Java 中将 RTF 转换为 PDF (含批量转换)
java
白宇横流学长1 小时前
基于SpringBoot医院复查开药网站和微信小程序的设计
spring boot·后端·微信小程序