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

}

显式指定路径参数名。

相关推荐
专注写bug11 分钟前
Java——pdf增加水印
java·pdf
橘子青衫17 分钟前
Java线程调度机制剖析:机制、状态与优先级管理
java·后端
Cloud_.32 分钟前
蓝桥杯-小明的背包(动态规划-Java)
java·蓝桥杯·动态规划·01背包·蓝桥杯算法实战分享
Better Rose40 分钟前
【2024年蓝桥杯Java B组】省赛真题详细解析
java·蓝桥杯
2401_897930061 小时前
微信小程序中的openid的作用
java
爱的叹息1 小时前
Spring MVC与Spring Boot文件上传配置项对比
spring boot·spring·mvc
毕小宝2 小时前
Java 解析日期格式各个字段含义温习
java
pwzs2 小时前
Spring 框架的核心基础:IoC 和 AOP
java·后端·spring
xrkhy2 小时前
java基础语法(3)数组
java·开发语言
hweiyu002 小时前
idea解决tomcat项目页面中文乱码
java·ide·tomcat·intellij-idea·intellij idea