报错信息

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);
}
显式指定路径参数名。