【Java异常】Feign常见的坑总结之一:Method Not Allowed“,“message“:“Request method ‘POST‘ not supported“,“path“:“/*
feign传递参数遇到的问题之一
背景描述:服务A要调用服务B的接口
服务A的接口(创建产品)为:注意这里请求的方式为POST
/**
* 同步添加研发产品
*
* @param productRequest 研发产品请求参数
* @return 添加后的研发产品
*/
@RequestMapping(value = "/product/create", method = RequestMethod.POST)
CommResponse<ProductResponse> create(@RequestBody ProductRequest productRequest);
服务B的接口(创建产品)为: 注意这里的接受的请求方式为PUT
@Api(value = "product", tags = "研发产品API")
@RequestMapping("/product")
public interface ProductApi {
@PutMapping("/create")
@ApiImplicitParam(name = "itemRequest",value = "研发产品",dataType = "ProductRequest",required = true,paramType = "body")
CommResponse<ProductResponse> create(@RequestBody ProductRequest itemRequest) ;
}
然后服务A调用服务B,结果后台报错
Caused by: feign.FeignException: status 405 reading WorkerFeignServiceClient#test(Map); content:
{“timestamp”:1506147245404,”status”:405,”error”:”Method Not Allowed”,”exception”:”org.springframework.web.HttpRequestMethodNotSupportedException”,”message”:”Request method ‘POST’ not supported”,”path”:”/product/create”}
报错内容意思为,这个方法不支持POST请求方式。
知道这个之后,那就容易改了,把POST请求方式改为被调用的服务B的接口的PUT请求方式,如下为改过之后的服务A的接口:
/**
* 同步添加研发产品
*
* @param productRequest 研发产品请求参数
* @return 添加后的研发产品
*/
@RequestMapping(value = "/product/create", method = RequestMethod.PUT)
CommResponse<ProductResponse> create(@RequestBody ProductRequest productRequest);
改过之后,再次调用服务B的接口,一切正常,可以调通。
完结!
还没有评论,来说两句吧...