【发布时间】:2018-07-26 22:04:42
【问题描述】:
我有一个简单的 REST API,我只返回 Resonse.ok().build(),因为函数的主体是异步的
我期待一个带有 200 http 状态代码的空响应,但我得到了一个完整的描述,似乎是作为实体的响应调用。
我做错了什么?
这是我从 API 调用收到的 json 响应
{
"context": {
"headers": {},
"entity": null,
"entityType": null,
"entityAnnotations": [],
"entityStream": {
"committed": false,
"closed": false
},
"length": -1,
"language": null,
"location": null,
"committed": false,
"mediaType": null,
"allowedMethods": [],
"links": [],
"entityTag": null,
"stringHeaders": {},
"lastModified": null,
"date": null,
"acceptableMediaTypes": [
{
"type": "*",
"subtype": "*",
"parameters": {},
"quality": 1000,
"wildcardType": true,
"wildcardSubtype": true
}
],
"acceptableLanguages": [
"*"
],
"entityClass": null,
"responseCookies": {},
"requestCookies": {},
"lengthLong": -1
},
"status": 200,
"length": -1,
"language": null,
"location": null,
"metadata": {},
"cookies": {},
"mediaType": null,
"allowedMethods": [],
"links": [],
"statusInfo": "OK",
"entityTag": null,
"stringHeaders": {},
"entity": null,
"lastModified": null,
"date": null,
"headers": {}
}
REST api 看起来像这样
@RestController
@RequestMapping("/accountworkers")
@Api(value = "/updater")
public class AccountUpdater {
private static Logger LOGGER = LoggerFactory.getLogger(AccountUpdater.class);
@Autowired
private AccountUpdaterController auController;
@RequestMapping(value = "/updater", method = RequestMethod.GET)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response runUpdater() {
LOGGER.info("Running account updater");
auController.doAccountUpdateAsync();
return Response.ok().build();
}
}
【问题讨论】:
标签: rest spring-mvc jax-rs