在feign调用时,客户端get请求,服务端接受也是get请求,但是执行请求报错 Method Not Allowed: Request method ‘POST’ not supported

1.feign客户端

@GetMapping(“/list”) Result queryPageList(SystemAccountBookDetail systemAccountBookDetail, @RequestParam(name = “pageNo”, defaultValue = “1”) Integer pageNo, @RequestParam(name = “pageSize”, defaultValue = “10”) Integer pageSize) {

return sysAccountBookDetailService.queryPageList(systemAccountBookDetail,pageNo,pageSize);

}

2.feign服务端

@Component

@FeignClient(value = FeignConstant.OCP_CLOUD_SYSTEM, fallbackFactory = AccountAPIFallbackFactory.class)

public interface AccountApi {

@GetMapping(value = "/account/accountBookDetail/list")

Result accountBookDetailPageList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,

@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,

SystemAccountBookDetail systemAccountBookDetail);

}

原因:因为使用了SystemAccountBookDetail 对象,而在feign调用中无法识别是否为get/post 请求,因此强转成了post请求,导致在服务端报错Method Not Allowed: Request method ‘POST’ not supported

解决:在feign服务端api中,加上注解@SpringQueryMap 即可解决,注解的作用是将实体转成表单数据

如下:

@Component

@FeignClient(value = FeignConstant.OCP_CLOUD_SYSTEM, fallbackFactory = AccountAPIFallbackFactory.class)

public interface AccountApi {

@GetMapping(value = "/account/accountBookDetail/list")

Result accountBookDetailPageList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,

@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,

SystemAccountBookDetail systemAccountBookDetail);

}

参考文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: