@FeignClient 将@GetMapping 与@RequestBody 强制为POST
@FeignClient forces @GetMapping with @RequestBody to POST
我有以下带有 GET 方法的 REST 控制器,该方法具有 BODY,适用于测试和邮递员
@RestController
@RequestMapping(value = "/xxx")
public class Controller {
@GetMapping({"/find"})
public LocalDateTime findMax(@RequestBody List<ObjectId> ids) {
//return sth
}
}
但是使用FeignClient调用服务时,会生成一个POST请求(忽略@GetMapping注解)
@FeignClient
public interface CoveragesServiceResource extends CoveragesService {
@GetMapping({"/find"})
LocalDateTime findMax(@RequestBody List<ObjectId> ids);
}
出现错误:
Request method 'POST' not supported
GET 请求在技术上可以有正文,但正文应该没有意义,因为 explained in this answer. You might be able to declare a GET endpoint with a body but some network libraries and tools will simply not support it e.g. Jersey can be configured to allow it but RESTEasy can't 。
建议将 /find
声明为 POST 或不使用 @RequestBody
。
我有以下带有 GET 方法的 REST 控制器,该方法具有 BODY,适用于测试和邮递员
@RestController
@RequestMapping(value = "/xxx")
public class Controller {
@GetMapping({"/find"})
public LocalDateTime findMax(@RequestBody List<ObjectId> ids) {
//return sth
}
}
但是使用FeignClient调用服务时,会生成一个POST请求(忽略@GetMapping注解)
@FeignClient
public interface CoveragesServiceResource extends CoveragesService {
@GetMapping({"/find"})
LocalDateTime findMax(@RequestBody List<ObjectId> ids);
}
出现错误:
Request method 'POST' not supported
GET 请求在技术上可以有正文,但正文应该没有意义,因为 explained in this answer. You might be able to declare a GET endpoint with a body but some network libraries and tools will simply not support it e.g. Jersey can be configured to allow it but RESTEasy can't
建议将 /find
声明为 POST 或不使用 @RequestBody
。