我想在我的 Spring Boot 應用程序中為匹配/async/*. 例子:localhost:8080/async/downloadLargeFilelocalhost:8080/async/longRunningRask以第一個例子為例,我使用如下方法實現了我的方法StreamingResponseBody:@GetMappingpublic ResponseEntity<StreamingResponseBody> downloadLargeFile() throws IOException { long size = Files.size(path); InputStream inputStream = Files.newInputStream(path); return ResponseEntity.ok() .contentLength(size) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=large_file.txt") .body(inputStream::transferTo);}在 的文檔中StreamingResponseBody,它指出我應該配置一個AsyncTaskExecutor,所以我有這個 @Configuration 類也實現WebMvcConfigurer了:@Configurationpublic class AsyncConfigurer implements WebMvcConfigurer { @Override public void configureAsyncSupport(AsyncSupportConfigurer configurer) { configurer.setDefaultTimeout(-1); configurer.setTaskExecutor(asyncTaskExecutor()); } @Bean public AsyncTaskExecutor asyncTaskExecutor() { return new SimpleAsyncTaskExecutor("async"); }}但是,我找不到僅對匹配給定模式的請求使用此任務執行器的方法。作為一個更一般的問題 -我如何限制WebMvcConfigurer只適用于匹配模式的請求子集?如果這不可能或不推薦,那么完成相同行為的正確方法是什么?
添加回答
舉報
0/150
提交
取消