title: Why am I getting a WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped exception?
body: <p>I've looked at other questions relating to this error on the site but most of them are either about SessionScope or are unanswered. The only possibly helpful one is <a href="https://stackoverflow.com/questions/26631093/no-active-contexts-for-scope-type-javax-enterprise-context-requestscoped-when-in">No active contexts for scope type javax.enterprise.context.RequestScoped when invoking a bean from a thread</a> but it's not in the context I have.</p>
  
  <p>I'm running a JAX-RS endpoint on Wildfly 10.1 (Java ee 7). Looks something like this:</p>
  
  <pre><code>@Path("")
  public class ServerResource {
  
      @Inject
      Order order;
  
      @Resource
      ManagedExecutorService mes;
  
      @PUT
      @Path("/prepareOrder")
      public void prepareOrder(@Suspended AsyncResponse response) {
          mes.execute(() -&gt;  {
              try {
                  Item item = new Item(); // JPA entity
                  order.setItem(item); // line 71
                  // call a service to save the order data (like item) to the DB
              } catch (Exception e) {
                  e.printStackTrace();
                  response.resume(false);
              }
              response.resume(true);
          });
      }
  }
  </code></pre>
  
  <p>I added the try-catch only because of this problem, it's not generally there.  <code>Order</code> is</p>
  
  <pre><code>@Stateful
  @RequestScoped
  public class Order {
      private Item item;
      // setter and getter
  }
  </code></pre>
  
  <p>Order is RequestScoped because when it's being used/processed it goes through a sort of chain of responsibility (several Stateless beans that inject the Order and change it in sequence). Anyway the question is not about the design but about the error.</p>
  
  <p>The line <code>order.setItem(item);</code> throws the exception:</p>
  
  <pre><code>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:689)
  at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
  at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:165)
  at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
  at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
  at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)
  at com.a.b.Order$Proxy$_$$_WeldClientProxy.setItem(Unknown Source)
  at com.a.c.ServerResource.lambda$0(ServerResource.java:71)
  at org.jboss.as.ee.concurrent.ControlPointUtils$ControlledRunnable.run(ControlPointUtils.java:105)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at org.glassfish.enterprise.concurrent.internal.ManagedFutureTask.run(ManagedFutureTask.java:141)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  at java.lang.Thread.run(Thread.java:748)
  at org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:250)
  </code></pre>
  
  <p>I tried to annotate the ServerResource class with <code>@Stateless</code> or <code>RequestScope</code> (<a href="https://stackoverflow.com/questions/20558125/stateless-vs-requestscoped">@Stateless vs @RequestScoped</a>) but it didn't matter.</p>
  
  <p>Why do I get this error and how do I get my code working?</p>