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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

怎么解決自定義線程 RequestContextHolder.getRequestAttributes返回null?

怎么解決自定義線程 RequestContextHolder.getRequestAttributes返回null?

鴻蒙傳說(shuō) 2019-01-17 01:33:46
問(wèn)題描述 使用Spring框架,在Service中開啟一個(gè)新的線程,在新的線程中使用RequestAttributes ra = RequestContextHolder.getRequestAttributes();獲取出來(lái)為null,有沒(méi)有什么辦法能解決? 問(wèn)題出現(xiàn)的環(huán)境背景及自己嘗試過(guò)哪些方法 Service中為優(yōu)化響應(yīng)時(shí)間,使用了多線程,部分線程中使用到了RequestContextHolder類,結(jié)果返回值為空。 相關(guān)代碼 RequestAttributes ra = RequestContextHolder.getRequestAttributes();ServletRequestAttributes sra = (ServletRequestAttributes) ra;HttpServletRequest request = sra.getRequest();System.out.println(request.getContextPath()); 你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么? 期待:System.out.println(request.getContextPath());正常打印出路徑,實(shí)際:RequestAttributes ra = RequestContextHolder.getRequestAttributes(); ra為null.
查看完整描述

1 回答

?
拉丁的傳說(shuō)

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊

開啟新線程之前,添加代碼:
//將RequestAttributes對(duì)象設(shè)置為子線程共享
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
RequestContextHolder.setRequestAttributes(sra, true);

查看完整回答
反對(duì) 回復(fù) 2019-02-12
  • 1 回答
  • 0 關(guān)注
  • 949 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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