亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 Spring Boot WebMvcConfigurer 限制為僅指定路徑

將 Spring Boot WebMvcConfigurer 限制為僅指定路徑

阿波羅的戰車 2022-12-28 15:38:58
我想在我的 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只適用于匹配模式的請求子集?如果這不可能或不推薦,那么完成相同行為的正確方法是什么?
查看完整描述

1 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

TaskExecutor為/與WebMvcConfigureron配置時,AsyncSupportConfigurer將僅用于 Web 請求的異步處理。所有其他請求都由您的 servlet 容器上可用的默認請求處理線程處理。

異步性質由方法的返回類型定義。異步類型在 Spring 參考指南的MVC 異步部分進行了描述。


查看完整回答
反對 回復 2022-12-28
  • 1 回答
  • 0 關注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號