Question

I have this class to produces some Java EE resources. My project is a EAR with EJB and CDI.

public class Resources {

    @Dependent
    @Produces
    @Resource(mappedName = "java:comp/EJBContext")
    protected SessionContext sessionContext;
}

And it's works fine in JBoss AS 7. But when I use Wildfly (beta1 compiled from github today), I'm getting this exception.

Caused by: org.jboss.weld.exceptions.NullInstanceException: WELD-000044: Unable to obtain instance from null

What's wrong? How I can produces SessionContext using Wildfly? There is a different way in Wildfly, or it's a bug (since Wildfly are not ready for production yet)?

Update Using the last version of Wildfly compiled from Github, this code works fine. I think that it was a expected bug, since Wildfly is beta. Thank you guys.

Was it helpful?

Solution

SessionContext is context related to current session bean. in your case Resources class is not any kind of ejb bean, that is why SessionContext is not injected.

try adding @Stateless to Resources class. In any case it seems bit odd that you want to create producer for SessionContext which is valid just for current bean. see javadoc on where SC is valid and what does it relate to http://docs.oracle.com/javaee/7/api/javax/ejb/SessionContext.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top