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

}

显式指定路径参数名。

相关推荐
oak隔壁找我13 分钟前
Servlet 三大组件详解
java·后端
南部余额18 分钟前
Spring MVC 拦截器interceptor
java·spring·mvc
oak隔壁找我27 分钟前
SpringBoot 实现 JWT 认证完整方案
java·后端
Touch&39 分钟前
Spring5.3.10源码编译和调试(IDEA+Gradle)的过程
spring·framework·gradle·idea·spring源码编译
程序_白白42 分钟前
探讨一下java将来未来两年内的就业以及发展
java·开发语言
oak隔壁找我1 小时前
RabbitMQ 实现延迟通知的完整方案
java·后端
信码由缰1 小时前
Java的优势有哪些
java
trow1 小时前
ConcurrentHashMap线程安全实现详解
java·后端
trow1 小时前
HashMap核心原理与源码剖析
java·后端
可观测性用观测云2 小时前
云原生架构下微服务接入 SkyWalking 最佳实践
java