【发布时间】:2018-08-21 21:15:03
【问题描述】:
来自 .NET 和 Node 我真的很难弄清楚如何将这个阻塞的 MVC 控制器转移到一个非阻塞的 WebFlux 注释控制器?我已经理解了这些概念,但找不到合适的异步 Java IO 方法(我希望它返回 Flux 或 Mono)。
@RestController
@RequestMapping("/files")
public class FileController {
@GetMapping("/{fileName}")
public void getFile(@PathVariable String fileName, HttpServletResponse response) {
try {
File file = new File(fileName);
InputStream in = new java.io.FileInputStream(file);
FileCopyUtils.copy(in, response.getOutputStream());
response.flushBuffer();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java spring spring-boot spring-webflux