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

}

显式指定路径参数名。

相关推荐
h7ml13 分钟前
企业微信 API 与内部系统集成时的 OAuth2.0 安全上下文传递机制
java·安全·企业微信
Konata1213 分钟前
实现进阶的C/S通信
java·开发语言
初听于你15 分钟前
Java 泛型详解
java·开发语言·windows·java-ee
rainbow688916 分钟前
Java17新特性深度解析
java·开发语言·python
爬山算法17 分钟前
Hibernate(79)如何在ETL流程中使用Hibernate?
java·hibernate·etl
rainbow688923 分钟前
Java实战:5230台物联网设备时序数据处理方案
java
爬山算法23 分钟前
Hibernate(80) 如何在数据迁移中使用Hibernate?
java·oracle·hibernate
Elias不吃糖26 分钟前
Day1 项目启动记录(KnowledgeDock)
java·springboot·登陆·项目启动
belldeep26 分钟前
Java:Tomcat 9, flexmark 0.6 和 mermaid.min.js 10.9 实现 Markdown 中 Mermaid 图表的渲染
java·tomcat·mermaid·flexmark
小马爱打代码27 分钟前
Spring Boot:Sentinel 企业级熔断、降级与限流实战
spring boot·后端·sentinel