Spring MVC中是否存在JAX-RS StreamingOutput
的类似内容?我最初的任务是释放一个服务线程来写一个大的响应。
答案 0 :(得分:0)
您可以尝试返回InputStreamResource
,as exemplified by Sergey Petunin的实例:
@RequestMapping(value = "/stream", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public Resource getStream() {
String string = "Hello World!";
// acquiring the stream
InputStream stream = new ByteArrayInputStream(string.getBytes());
// counting the length of data
final long contentLength = string.length();
return new InputStreamResource(stream){
@Override
public long contentLength() throws IOException {
return contentLength;
}
};
}