title: EJB injection into non managed objects
body: <p>we are upgrading our web application to Oracle WebLogic 12c with EJB 3.x, and we got an issue.</p>
  
  <p>This is the scenario...</p>
  
  <p>We have a simple EJBs that we are going to call MyService, defined with its bean and local/remote interfaces defined by the EJB 3.x annotations.</p>
  
  <p>Here is a pseudo code of the scenario:</p>
  
  <pre><code>class MyListener implements ServletContextListener {
  
      @EJB private MyService myService;
  
      public void contextInitialized(ServletContextEvent arg0) {
          // Here myService is correctly instantiated, so we do something...
      }
  
  }
  </code></pre>
  
  <p>Now we have to move the contextInitialized method logic inside an utility class, so the new scenario will be:</p>
  
  <pre><code>class MyUtility {
  
    @EJB private MyService myService;
  
    public void doSomething() {
        // Here myService is NULL!!!!!
    }
  
  }
  
  class MyListener implements ServletContextListener {
  
      public void contextInitialized(ServletContextEvent arg0) {
          new MyUtility().doSomething();
      }
  
  }
  </code></pre>
  
  <p>I have read a lot of documentation about that problem, and I discovered that only some kind of classes are scanned by the Application Server to resolve the injected EJBs ( <a href="https://stackoverflow.com/questions/11122127/java-ee-6-5-7-list-of-managed-beans-or-classes-ejbs-jsf-beans-and">Java EE 6, 5, 7 | List of managed beans or classes: EJBs , JSF beans and ..?</a> ).</p>
  
  <p>Is there a workaround to force the scanning of a custom class like mine with WebLogic?</p>
  
  <p>Thank you very much.</p>