title: Jersey and EJB stateless example, EJB instance is null
body: <p>I am making a simple RESTful service using JAVAX RS and EJB in order to create a singleton object as a global variable.</p>
  
  <p>I initiated the service as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>    import org.glassfish.grizzly.http.server.HttpServer;
      import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
      import org.glassfish.jersey.server.ResourceConfig;
  
      final ResourceConfig rc = new ResourceConfig().packages("service_folder");
      GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
  </code></pre>
  
  <p>I am currently just testing the @Stateless example.</p>
  
  <p>Firstly, I create a class in a random folder, and the content as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>    import javax.ejb.Stateless;
      import java.util.Date;
  
  
      @Stateless
      public class Service {
          public Date getCurrentDate(){
              return new Date();
          }
      }
  </code></pre>
  
  <p>Then I create the resource file in the <strong>service_folder</strong> mentioned in the very beginning:</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Stateless
      @Path("current")
      public class ServiceFacade {
  
          @EJB
          Service service;
  
          @GET
          public String getDate(){
              return service.getCurrentDate().toString();
          }
  
      }
  
  </code></pre>
  
  <p>The current situation is that whenever I access <em>BASE_URI/current</em>, grizzly simply throw an error, and the reason is because <strong>service</strong> in getDate() is null.</p>
  
  <p>My guess is that during the grizzly init., the Service class bean isn't really registered yet.</p>
  
  <p>Please let me know where did I do wrong, thanks!</p>