Java 带补丁动词的请求
我有两个微型服务。第一个具有符合以下代码的端点:Java 带补丁动词的请求,java,spring-boot,rest,Java,Spring Boot,Rest,我有两个微型服务。第一个具有符合以下代码的端点: @RequestMapping(value = "/threshold/update/{id}/{valor}/{status}", method = RequestMethod.GET) public Threshold updateThreshold(@PathVariable String id, @PathVariable String valor, @PathVariable Boolean status) {
@RequestMapping(value = "/threshold/update/{id}/{valor}/{status}", method = RequestMethod.GET)
public Threshold updateThreshold(@PathVariable String id, @PathVariable String valor, @PathVariable Boolean status) {
return thresholdQuery.updateThreshold(id,valor,status);
}
String url = new StringBuilder().append("http://localhost:8080/threshold/update/").append(id).append("/").append(valor).append("/").append(status).toString();
Threshold threshold = restTemplate.patchForObject(url, HttpMethod.PATCH, Threshold.class);
@RequestMapping(value = "/threshold/update/{id}/{valor}/{status}", method = RequestMethod.PATCH)
public Threshold updateThreshold(@PathVariable String id, @PathVariable String valor, @PathVariable Boolean status) {
return thresholdQuery.updateThreshold(id,valor,status);
}
第一个向第二个微服务发出请求,代码如下:
@RequestMapping(value = "/threshold/update/{id}/{valor}/{status}", method = RequestMethod.GET)
public Threshold updateThreshold(@PathVariable String id, @PathVariable String valor, @PathVariable Boolean status) {
return thresholdQuery.updateThreshold(id,valor,status);
}
String url = new StringBuilder().append("http://localhost:8080/threshold/update/").append(id).append("/").append(valor).append("/").append(status).toString();
Threshold threshold = restTemplate.patchForObject(url, HttpMethod.PATCH, Threshold.class);
@RequestMapping(value = "/threshold/update/{id}/{valor}/{status}", method = RequestMethod.PATCH)
public Threshold updateThreshold(@PathVariable String id, @PathVariable String valor, @PathVariable Boolean status) {
return thresholdQuery.updateThreshold(id,valor,status);
}
第二个微服务根据以下代码接收此请求:
@RequestMapping(value = "/threshold/update/{id}/{valor}/{status}", method = RequestMethod.GET)
public Threshold updateThreshold(@PathVariable String id, @PathVariable String valor, @PathVariable Boolean status) {
return thresholdQuery.updateThreshold(id,valor,status);
}
String url = new StringBuilder().append("http://localhost:8080/threshold/update/").append(id).append("/").append(valor).append("/").append(status).toString();
Threshold threshold = restTemplate.patchForObject(url, HttpMethod.PATCH, Threshold.class);
@RequestMapping(value = "/threshold/update/{id}/{valor}/{status}", method = RequestMethod.PATCH)
public Threshold updateThreshold(@PathVariable String id, @PathVariable String valor, @PathVariable Boolean status) {
return thresholdQuery.updateThreshold(id,valor,status);
}
问题是我得到了以下错误:
I/O error on PATCH request for \"http://localhost:8080/threshold/update/bola/dog/true\": Invalid HTTP method: PATCH; nested exception is java.net.ProtocolException: Invalid HTTP method: PATCH"
请参阅以获得解决方法。根据以下代码:restemplate.exchange(uri、HttpMethod.PATCH、entity、Void.class);问题是,我不需要向端点发送实体。我是否可以使用其他restTemplate方法?我改为:String aux=“”;HttpEntity requestEntity=新的HttpEntity(aux);字符串url=new StringBuilder().append(“;ResponseEntity threshold=restTemplate.exchange(url,HttpMethod.PATCH,requestEntity,threshold.class);返回threshold.getBody();但仍然是相同的错误。如果不发送实体,如何使用路径变量进行修补?您使用的是哪个版本的Spring Boot?我使用的是路径变量。我使用的是较新版本的Spring Boot。