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

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

如何在異步任務(wù)執(zhí)行程序中啟用請(qǐng)求范圍

如何在異步任務(wù)執(zhí)行程序中啟用請(qǐng)求范圍

猛跑小豬 2019-09-02 08:59:48
在我的應(yīng)用程序中,我有一些異步Web服務(wù)。服務(wù)器接受請(qǐng)求,返回OK響應(yīng)并使用AsyncTaskExecutor啟動(dòng)處理請(qǐng)求。我的問題是如何在此處啟用請(qǐng)求范圍,因?yàn)樵诖颂幚碇形倚枰@取注釋的類:@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)現(xiàn)在我得到例外:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.requestContextImpl': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.因?yàn)樗\(yùn)行SimpleAsyncTaskExecutor而不是運(yùn)行DispatcherServlet我的異步處理請(qǐng)求taskExecutor.execute(new Runnable() {    @Override    public void run() {        asyncRequest(request);    }});taskExecutor的位置是:<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
查看完整描述

3 回答

?
小唯快跑啊

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

由于原始父請(qǐng)求處理線程可能已將響應(yīng)提交到客戶端并且所有請(qǐng)求對(duì)象都已銷毀,因此無法在子異步線程中獲取請(qǐng)求范圍對(duì)象。處理此類方案的一種方法是使用自定義范圍,如SimpleThreadScope。


SimpleThreadScope的一個(gè)問題是子線程不會(huì)繼承父范圍變量,因?yàn)樗趦?nèi)部使用簡(jiǎn)單的ThreadLocal。要克服該實(shí)現(xiàn)自定義范圍,它與SimpleThreadScope完全相似,但在內(nèi)部使用InheritableThreadLocal。有關(guān)更多信息,請(qǐng)參閱 Spring MVC:如何在生成的線程中使用請(qǐng)求范圍的bean?


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

添加回答

舉報(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)