5 Replies Latest reply on Aug 22, 2010 12:19 PM by John Ament

    Inject ejb into class in war

    Rick Kilcoyne Newbie

      Having an issue with a null reference when injecting an EJB.


      The following class is in a war file that depends upon a separate jar containing my DeviceService EJB:


      @Path("/")
      public class Rest {
      
           protected @Inject
           DeviceService deviceService;
      
           @Path("/test")
           @GET
           @Produces(MediaType.TEXT_PLAIN)
           public String getTestMessage() {
                return "Rest#getTestMessage()";
           }
      
           @Path("/test2")
           @GET
           @Produces(MediaType.TEXT_PLAIN)
           public String getTestMessage2() {
                return deviceService.getTestMessage();
           }
      }
      



      EJB Local interface:


      @Local
      public interface DeviceService {
      
           public String getTestMessage();
      
      }



      EJB Implementation:


      public @Stateless
      class DeviceServiceBean implements DeviceService {
      
           public DeviceServiceBean() {
           }
      
           @Override
           public String getTestMessage() {
                return "DeviceServiceBean#getTestMessage()";
           }
      
      }



      When executed via resteasy, the deviceService reference is null. My ejb jar contains the beans.xml file and properly registers my EJB. I'm not sure if this is a Weld or RESTeasy issue.


      Suggestions are greatly appreciated!


      Rick