SpringCloud使用Feign调用其他客户端带参数的接口,传入参数为null或报错status 405 reading IndexService#del(Integer);

SpringCloud使用Feign调用其他客户端带参数的接口,传入参数为null或报错status 405 reading IndexService#del(Integer); 

第一种方法:

如果你的API为Restful 方式的可以在Client接口参数中加注解@PathVariable

@FeignClient(name = "PRODUCT")
@Component
public interface ProductClient {

    @PostMapping("/product/getMsgByGet/{a}")
    String getMsg(@PathVariable("a") String a);

}

第二种方法:

不是Restful形式的API 在Client接口参数加注解@ReuqstParam

@FeignClient(name = "PRODUCT")
@Component
public interface ProductClient {
    @PostMapping("/product/getMsgByGet")
    String getMsg(@RequestParam String a);
}

不加这两个注解的话目标服务可能会无法识别参数,造成错误。

原文地址:https://www.cnblogs.com/yueguanguanyun/p/10416733.html