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

}

显式指定路径参数名。

相关推荐
咸鱼2.019 小时前
【java入门到放弃】VUE部分知识点
java·javascript·vue.js
浔川python社19 小时前
《C++ 小程序编写系列》(第六部)
java·网络·rpc
码界奇点19 小时前
基于前后端分离架构的智能面试刷题系统设计与实现
spring boot·面试·职场和发展·架构·毕业设计·源代码管理
それども19 小时前
怎么理解 HttpServletRequest @Autowired注入
java
牧小七19 小时前
java JShell 怎么使用
java
小毅&Nora20 小时前
【Java线程安全实战】⑭ ForkJoinPool深度剖析:分治算法的“智能厨房“如何让并行计算跑得更快
java·算法·安全
晴天飛 雪20 小时前
Spring Boot 接口耗时统计
前端·windows·spring boot
开开心心就好20 小时前
打印机驱动搜索下载工具,自动识别手动搜
java·linux·开发语言·网络·stm32·物联网·电脑
yangminlei20 小时前
基于 Java 的消息队列选型年度总结:RabbitMQ、RocketMQ、Kafka 实战对比
java·java-rocketmq·java-rabbitmq
张np20 小时前
java基础-ListIterator 接口
java·开发语言