[英]Java - RestTemplate syntax error?
So I've got this controller method, which is obviously returning a ResponseEntity: 所以我有了这个控制器方法,显然是在返回一个ResponseEntity:
@RequestMapping(method=RequestMethod.POST, value="sendEmail")
public ResponseEntity sendPasswordResetEmail (@RequestParam("name") final String name,
@RequestParam("password") final String password,
@RequestParam("email") final String email)
{
final boolean success = notificationService.sendPasswordResetEmail(name, password, email);
return success ?
new ResponseEntity(HttpStatus.OK) : new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
}
My problem is that when calling the following, it is not letting me set ResponseEntity.class as the third parameter, which does not makes sense because that is the expected returning type: 我的问题是,调用以下命令时,不是让我将ResponseEntity.class设置为第三个参数,这没有意义,因为这是预期的返回类型:
ResponseEntity<String> auth = restTemplate.postForEntity(url, entity, ResponseEntity.class);
Any hint? 有什么提示吗?
UPDATE: 更新:
How is it possible that the code compiles and runs and I get this when consuming the endpoint? 代码如何编译和运行,并且在使用端点时得到了此信息?
{
"timestamp": 1444927133682,
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.NoClassDefFoundError",
"message": "org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/api/model/postmark/ResetPassword",
"path": "/v1/api/notify/sendPasswordResetEmail"
}
The signature of the postForEntity
method you are attempting to use is 您尝试使用的postForEntity
方法的签名是
public <T> ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType) throws RestClientException
In other words, it's always going to return a ResponseEntity
. 换句话说,它总是要返回ResponseEntity
。 What you are providing as an argument is the type of the response body, which will tell the RestTemplate
how to deserialize the content. 您作为参数提供的是响应主体的类型,它将告诉RestTemplate
如何反序列化内容。
Simply use 只需使用
ResponseEntity<String> auth = restTemplate.postForEntity(url, entity, String.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.