On 1/17/2013 2:54 AM, Mark Struberg wrote:
Hi Mike, that's an easy one :)
Well glad to hear, I spent a few hours scratching my head on this one
last night.
You tried to access a @javax.inject.Singleton scoped bean in a Thread where
this context didn't get activated.
Maybe it is just the wording of the exception that confused me. It
would have been useful to know what bean I was trying to access. Also,
based on my (limited) knowledge, I would have assumed the Singleton
scope always existed. I haven't read the spec, but based on the Java
Docs, it just says "the Injector will only instantiate once", nothing
about its lifecycle (nor lack of one).
I generally recommend against using the atinject @Singleton! Contrary to the
javax.ejb.Singleton it has an undefined lifecycle, so it's barely useful.
Please use a simple @ApplicationScoped instead.
That is good to know. I'm replacing all "@Singleton" with
"@ApplicationScoped" now and I'll see how it goes. It is effecting
things somehow as a handful of my unit tests are failing.
Thanks for the quick response.
Mike
LieGrue,
strub
PS: if you start new Threads manually yourself, then please look at
DeltaSpike-CdiCtrl ContextControl.
----- Original Message -----
From: Mike Olson <[email protected]>
To: [email protected]
Cc:
Sent: Thursday, January 17, 2013 9:52 AM
Subject: WebBeans context with scope type annotation @Singleton does not exist
within current thread
Hello,
I am trying to figure out exactly what this exception is trying to tell me.
I
have multiple web applications that are communicating with JMS and this is
occurring during a MessageListener call back so my assumption is that it has
something to do with being multi-threaded. However, I am also using the
"Provider" again so it could be another issue with that.
I am doing something similar to:
@Inject
Provider<Foo> fooProvider;
public void onMessage(Message m) {
fooProvider.get();
}
In the ".get()" call is where the exception occurs. I have been
through the code and inspected all of the Inject fields in the class hierarchy
of "Foo". There are some that are scoped as @Singleton. I have
removed that scope from all of them, but I still get the same exception.
Anyone have any ideas? Here is the traceback.
Thanks
Mike
javax.enterprise.context.ContextNotActiveException: WebBeans context with scope
type annotation @Singleton does not exist within current thread
at
org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:351)
at
org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:861)
at
org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:759)
at
org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at
org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at
org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at
org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at
org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at
org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at
org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at
org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at
org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:132)
at
org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:872)
at
org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:753)
at
org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at
org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at
org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at
org.apache.webbeans.component.AbstractInjectionTargetBean.injectSuperFields(AbstractInjectionTargetBean.java:368)
at
org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:93)
at
org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at
org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at
org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at
org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:132)
at
org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:872)
at
org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:126)
-- Mike Olson
--
Mike Olson