I have a JAX-RS resource annotated with @RequestScoped that has injected (through @Inject) a singleton EBJ. This EJB has a SessioNContext instance variable injected via @Resource.
The problem occurs when I try to call any method on the EJB. The invocation fails with the root exception:
StandardWrapperValve[Jersey Servlet]: PWC1406: Servlet.service() for servlet Jersey Servlet threw exception java.lang.IllegalStateException: Exception attempting to inject Env-Prop: com.company.ws.config.ConfigService/sessionContext@Field-Injectable Resource. Class name = com.company.ws.config.ConfigService Field name=sessionContext@java.lang.String@com.company.ws.config.ConfigService/sessionContext@@ into class com.company.ws.config.ConfigService at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:137) at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:50) ... Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting ... Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/com.company.ws.config.ConfigService/sessionContext' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound for java:comp/env/com.company.ws.config.ConfigService/sessionContext [Root exception is java.lang.IllegalStateException: Illegal invocation type for EJB Context : SERVLET_INVOCATION]] ....
Surprisingly, this works if the call is made through an intermediary EJB.
Can someone shed some light on what's happening here?