我的工作在Reasteasy與異步作業的問題(http://docs.jboss.org/resteasy/docs/2.3.1.GA/userguide/ html_single/index.html的#async_job_service)。結合RestEasy的異步未能注入SessionScoped和RequestScoped豆與CDI
我發佈一個請求,將?asynch = true添加到url中,然後作業異步運行,但運行時,它可以正常使用@ApplicationScoped或@Singleton註釋bean,但不能訪問聲明的類的bean與@RequestScoped註釋,我總是碰到這樣的錯誤:?
org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:664)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:77)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:87)
at com.examplecompany.exampleproject.multitenancy.org$jboss$weld$bean-flat-ManagedBean-class_com$examplecompany$exampleproject$multitenancy$PersistenceContext_$$WeldClientProxy.setDb(org$jboss$weld$bean-flat-ManagedBean-class_com$examplecompany$exampleproject$multitenancy$PersistenceContext$$_WeldClientProxy.java)
at com.examplecompany.exampleproject.auth.oauth.secure.OAuthDelegate.filterHttp(OAuthDelegate.java:115)
at com.examplecompany.exampleproject.auth.oauth.secure.AuthorizationInterceptor.preProcess(AuthorizationInterceptor.java:59)
at com.examplecompany.exampleproject.auth.oauth.secure.org$jboss$weld$bean-flat-ManagedBean-com$examplecom[email protected]javax$enterprise$context$ApplicationScoped()@javax$ws$rs$ext$Provider()@org$jboss$resteasy$annotations$interception$SecurityPrecedence()@org$jboss$resteasy$annotations$interception$ServerInterceptor()${com$examplecompany$examplepr[email protected]javax$inject$Inject()$$}_$$_WeldClientProxy.preProcess(org$jboss$weld$bean-flat-ManagedBean-com$examplecom[email protected]javax$enterprise$context$ApplicationScoped()@javax$ws$rs$ext$Provider()@org$jboss$resteasy$annotations$interception$SecurityPrecedence()@org$jboss$resteasy$annotations$interception$ServerInterceptor()${com$examplecompany$examplepr[email protected]javax$inject$Inject()$$}_$$_WeldClientProxy.java)
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:247)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
at org.jboss.resteasy.core.AsynchronousDispatcher.invokeSuper(AsynchronousDispatcher.java:227)
at org.jboss.resteasy.core.AsynchronousDispatcher$1.call(AsynchronousDispatcher.java:267)
at org.jboss.resteasy.core.AsynchronousDispatcher$1.call(AsynchronousDispatcher.java:259)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
這個錯誤,如果我發佈了同樣的要求不添加非同步=真不會發生。
我進一步研究這個問題,並在我的代碼寫了下面的線
try {
Context context = beanManager.getContext(RequestScoped.class);
} catch (ContextNotActiveException e) {
logger.info("Oops the context does not exists, we are in bad sh*t",e);
}
如果我在異步模式下,ContextNotActiveException
始終拋出,日誌具有相同的異常消息WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
。
所以我想,當啓動任務異步模式下,兩個背景會話和請求不創建,並在這些範圍內定義這樣我的豆不可訪問。
我提出了票進去RestEasy的吉拉本:https://issues.jboss.org/browse/RESTEASY-682
好的一點,我試着改變'@SessionScoped'作爲'@ RequestScoped',但同樣的問題在這裏:'org.jboss.weld.context.ContextNotActiveException:WELD-001303沒有活動上下文作用域類型爲javax.enterprise .context.RequestScoped' – Nicocube 2012-03-14 15:18:18
我編輯了原文,以反映這一變化。實際上,我的問題只出現在只有異步請求的地方,而顯然CDI環境不可用。 :( – Nicocube 2012-03-14 15:26:26
奇6.7.1表明它應該是積極的。這是哪個服務器和版本? – LightGuard 2012-03-15 15:13:34