title: Injecting @EJB in OmniFaces @Eager bean causes "Severe: No valid EE environment for injection of org.omnifaces.cdi.eager.EagerBeansRepository"
body: <p>Using <code>@ApplicationScoped @Named @Eager</code>, my <code>@EJB</code>-injected <code>@Stateless</code> beans are not properly instantiated and evaluate to <code>null</code>.</p>
  
  <p>I had an <code>@ApplicationScoped @ManagedBean(eager=true)</code> that was used to schedule a few jobs. Some <code>@Stateless</code> beans were injected using <code>@EJB</code> annotation, and that worked fine.</p>
  
  <p>In the move to CDI annotations, I added the <a href="http://showcase.omnifaces.org/cdi/Eager" rel="nofollow">OmniFaces <code>@Eager</code></a> annotation as substitute for <code>@ManagedBean(eager=true)</code> which is missing in standard CDI:</p>
  
  <pre><code>import javax.annotation.PostConstruct;
  import javax.annotation.PreDestroy;
  import javax.ejb.EJB;
  import javax.enterprise.context.ApplicationScoped;
  import javax.inject.Inject;
  import javax.inject.Named;
  import org.omnifaces.cdi.Eager;
  
  @Named
  @ApplicationScoped
  @Eager
  public class MyScheduler implements Serializable {
  
      @EJB
      private MyService myService;
      @Inject
      private MyNamedBean myNamedBean;
  
      @PostConstruct
      public void init() {
          setupSchedulers();
      }
  
      @PreDestroy
      public void destroy() {
          destroySchedulers();
      }
      //...
  }
  </code></pre>
  
  <p>Using this setup, the <code>@PostConstruct</code> method is correctly called on application startup (though it seems to run even before the context is initialized), but then <code>myService</code> evaluates to <code>null</code>.</p>
  
  <p>In the log, the following warnings appear:</p>
  
  <pre><code>Severe:   No valid EE environment for injection of org.omnifaces.cdi.eager.EagerBeansRepository
  Severe:   No valid EE environment for injection of my.package.MyScheduler
  Info:   Initializing Mojarra 2.2.8 ( 20140814-1418 https://svn.java.net/svn/mojarra~svn/tags/2.2.8@13507) for context '/tagific'
  </code></pre>
  
  <p>Since I need to access this bean from other ones, I couldn't use the <code>@Singleton</code> and <code>@Schedule</code> annotations.</p>
  
  <p>How could I properly inject <code>@Stateless</code> beans in an <code>@Named</code> applications scoped bean that would be instantiated on application startup?</p>