Inject ConversationScoped beans within an asynchronous method

I need to call a method annotated with @Asynchronous in EJB from a ConversationScoped bean. Inside this method I create instances of some classes using @Inject to inject ConversationScoped beans. Is it somehow possible to set the context of the asynchronous method to given Conversation?

I hope you can help me.


No, absolutely not. EJBs do per definition not run in web container, but in EJB container. In essence, having any web-related artifact/dependency (including javax.faces.* classes) inside an EJB class is a red alert. You're not supposed to inject/access any class from the client tier (the WAR) in the business tier (the EJB/EAR). Moreover, conversation scoped beans are tied to a HTTP request parameter and this information is nowhere available in an EJB container.

Whatever problem you're trying to solve and for which you incorrectly thought that this all would be the right solution, it has to be solved differently. As an educated guess, I think you just need to let the EJB fire a CDI event or take a callback argument.

See also:

Need Your Help

reconnect to database if connection restart

java jboss datasource

I have JBoss, and I am using JNDI to connect to database, but when database restarts, I have to restart JBoss to take new connection pool, are there any properties to do reconnection?, please help

Difference between defer().promise and Promise

javascript promise

I know defer separates promises states control and process, here using Q as an example, the promise returned by Q.defer().promise and Q.Promise is totally different, why designing in this way? and ...