Feign client get request, server throws Method Not Allowed: Request method 'POST' not supported

When feign is called, the client gets the request, and the server accepts the get request, but the execution request reports an error
Method Not Allowed: Request method 'POST' not supported
insert image description here

1. feign client

@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 server

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

}

Reason: Because the SystemAccountBookDetail object is used, it is not possible to identify whether it is a get/post request in the feign call, so it is forced to be a post request, resulting in an error Method Not Allowed: Request method 'POST' not supported on the server side

Solution: Add the annotation @SpringQueryMap in the feign server api to solve it. The function of the annotation is to convert the entity into form data

as follows:

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

}

Guess you like

Origin blog.csdn.net/weixin_43866043/article/details/129266599