第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

使用 @Async Spring 返回 null 的 HttpServletRequest 詳細信息

使用 @Async Spring 返回 null 的 HttpServletRequest 詳細信息

有只小跳蛙 2022-06-15 09:24:23
我想提取傳入請求的 URI。我的應(yīng)用程序中有以下代碼 -@RequestMapping即@Async. 我想通過提取路徑URI,request.getRequestURI()但是null當(dāng)@Async注釋存在時它會返回,否則,當(dāng)它不存在時,輸出是所需的。這是預(yù)期的行為,如果是,為什么?我怎樣才能獲得相同的輸出@Async?刪除@Async對我來說不是一個簡單的選擇,因為我想用它來提高性能。@Async@RequestMapping("{name}/**")@ResponseBodypublic void incomingRequest(        @PathVariable("name") String name,        HttpMethod method,        HttpServletRequest request,        HttpServletResponse response){    String URI = request.getRequestURI(); // <-- null with @Async}似乎總的來說,所有與請求相關(guān)的參數(shù)都在丟失,這不是我想要的;我需要為我的程序提取它們。
查看完整描述

1 回答

?
qq_笑_17

TA貢獻1818條經(jīng)驗 獲得超7個贊

我能找到的最接近空原因的線索HttpServletRequest是對這篇文章的答案的評論:HttpServletRequest 對象的生命是什么?

要解決您的問題,您可以在此處嘗試 2 種方法:

  1. 由于您的方法是您可以使用例如CompletableFuturevoid從方法手動啟動一個新線程。incomingRequest

  2. 或者,嘗試CompletableFuture從您的方法返回,如下所示:

@Async

@RequestMapping("{name}/**")

@ResponseBody

public CompletableFuture<Void> incomingRequest(

        @PathVariable("name") String name,

        HttpMethod method,

        HttpServletRequest request,

        HttpServletResponse response)

{

    String URI = request.getRequestURI(); // should get the right non null path

    return CompletableFuture.completedFuture(null);

}


查看完整回答
反對 回復(fù) 2022-06-15
  • 1 回答
  • 0 關(guān)注
  • 429 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號