所以我有这个控制器方法,显然返回了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);
}
我的问题是,当调用以下内容时,它不会让我将ResponseEntity.class设置为第三个参数,这没有意义,因为这是预期的返回类型:
ResponseEntity<String> auth = restTemplate.postForEntity(url, entity, ResponseEntity.class);
任何提示?
更新
代码如何编译和运行,我在使用端点时得到了这个?
{
"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"
}
答案 0 :(得分:1)
您尝试使用的postForEntity
方法的签名是
public <T> ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType) throws RestClientException
换句话说,它总是会返回ResponseEntity
。您作为参数提供的是响应主体的类型,它将告诉RestTemplate
如何反序列化内容。
只需使用
ResponseEntity<String> auth = restTemplate.postForEntity(url, entity, String.class);