java中spring微服务的HttpClientErrorException
我正在尝试创建2个微服务。第一次调用第二次(add方法应仅检查审核内容并设置approved标志)进行审核,但我仍收到异常java中spring微服务的HttpClientErrorException,java,microservices,Java,Microservices,我正在尝试创建2个微服务。第一次调用第二次(add方法应仅检查审核内容并设置approved标志)进行审核,但我仍收到异常org.springframework.web.client.HttpClientErrorException:405 null 这是我在第一微服务公司的休息时间 @RequestMapping(value = "/addreview", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_V
org.springframework.web.client.HttpClientErrorException:405 null
这是我在第一微服务公司的休息时间
@RequestMapping(value = "/addreview", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createReviewForMovie(@RequestBody Review review) {
ResponseEntity<Boolean> response = new RestTemplate().getForEntity("http://localhost:9100/add",
Boolean.class, review);
Boolean resultReview = response.getBody();
return new ResponseEntity<Boolean>(resultReview, HttpStatus.OK);
}
@RequestMapping(value=“/addreview”,method=RequestMethod.PUT,products=MediaType.APPLICATION\u JSON\u value)
公共响应性createReviewForMovie(@RequestBody Review){
ResponseEntity response=new RestTemplate()。getForEntity(“http://localhost:9100/add",
(上课、复习);
布尔结果视图=response.getBody();
返回新的ResponseEntity(resultReview,HttpStatus.OK);
}
第二个:
@RequestMapping(value = "/add", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> add(@RequestBody Review review){
if(review.getReviewContent().length()<10){
review.setApproved(false);
return new ResponseEntity<Boolean>(review.isApproved(), HttpStatus.OK);
}
review.setApproved(true);
return new ResponseEntity<Boolean>(review.isApproved(), HttpStatus.OK);
}
@RequestMapping(value=“/add”,method=RequestMethod.PUT,products=MediaType.APPLICATION\u JSON\u value)
公共响应添加(@RequestBody Review){
如果(review.getReviewContent().length(),问题是我对不同的微服务使用相同的模型类(review.class
),这不允许我执行请求
Add方法无法识别review
,因为我从另一个项目传递了它
在我重新编码后,它看起来是这样的:
@RequestMapping(value = "/addreview", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createReviewForMovie(@RequestBody Review review) {
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("reviewContent", review.getReviewContent());
uriVariables.put("userName", review.getUserName());
ResponseEntity<Boolean> response = new RestTemplate().getForEntity("http://localhost:9100/add/{reviewContent}/{userName}",
Boolean.class, uriVariables);
Boolean resultReview = response.getBody();
return new ResponseEntity<Boolean>(resultReview, HttpStatus.OK);
}
@RequestMapping(value=“/addreview”,method=RequestMethod.PUT,products=MediaType.APPLICATION\u JSON\u value)
公共响应性createReviewForMovie(@RequestBody Review){
Map uriVariables=newhashmap();
uriVariables.put(“reviewContent”,review.getReviewContent());
uriVariables.put(“userName”,review.getUserName());
ResponseEntity response=new RestTemplate()。getForEntity(“http://localhost:9100/add/{reviewContent}/{userName}”,
Boolean.class,URI变量);
布尔结果视图=response.getBody();
返回新的ResponseEntity(resultReview,HttpStatus.OK);
}
@RequestMapping(value=“/add/{reviewContent}/{userName}”,method=RequestMethod.GET,products=MediaType.APPLICATION\u JSON\u value)
公共响应属性添加(@PathVariable(“reviewContent”)字符串reviewContent,@PathVariable(“用户名”)字符串用户名){
如果(reviewContent.length()15){
返回新的响应状态(false,HttpStatus.OK);
}
返回新的ResponseEntity(true,HttpStatus.OK);
}
然而,我仍然很好奇是否还有其他方法可以使用Review.class
@RequestMapping(value = "/add/{reviewContent}/{userName}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> add(@PathVariable("reviewContent") String reviewContent, @PathVariable("userName") String userName){
if(reviewContent.length()<10){
return new ResponseEntity<Boolean>(false, HttpStatus.OK);
}else if(userName.length()>15){
return new ResponseEntity<Boolean>(false, HttpStatus.OK);
}
return new ResponseEntity<Boolean>(true, HttpStatus.OK);
}