RequestScoped beans in MessageDriven beans in wildfly
poths Feb 24, 2015 3:44 AMHi dear wildfly community,
I am using Wildfly 8.1.0 and expected the calls to MessageDriven beans having an open RequestScope so that I could inject my EntityManager via a RequestScoped provider.
Unfortunately I get the exception:
Caused by: 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:680)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:128)
at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:148)
at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:183)
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:789)
[...]
My message driven class looks roughly like this:
@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/OfferTopic"),
@ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Topic") })
@Transactional
public class TestMessageReceiver implements MessageListener {
@Inject
private EntityManager em;
@Override
public void onMessage(Message message) {
...
}
}
I can add more information if needed, but feel I might be completely on the wrong path. So here are my questions:
- Is the assumption correct, that I should have a request scope in the message driven bean? If not, in which CDI scope would I keep an entity manager?
- Can I programmatically create the request scope inside an Interceptor? I found some JBoss 7.1.2 code that seems to do this but I have a hard time reproducing this: http://grepcode.com/file/repo1.maven.org/maven2/org.jboss.as/jboss-as-weld/7.1.2.Final/org/jboss/as/weld/ejb/EjbRequestS…
Thank you very much for any hints into a better direction.