1 Reply Latest reply: Feb 25, 2013 5:01 AM by r035198x RSS

    calling singleton bean from a session bean returns NullPointerException

    991664
      I am doing this

      @Startup
      @Singleton
      @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
      @Lock(LockType.READ)
      public class ResourceBean {


      @PostConstruct
      private void init()
      {
      System.out.println("Resource Bean created successfully");
      }


      @Lock(LockType.WRITE)
      public String returnString(String name) {
      String n=name;
      return n;
      }


      }
      and i call this singleton bean from a stateless session bean like this


      @Stateless

      public class ClientBean {

      @EJB
      ResourceBean resource;



      public String create(String r)
      {
      String res=resource.returnString(r);
      return res;
      }

      }
      But resource.returnString(r); gives a org.apache.jasper.JasperException: java.lang.NullPointerException I started the glassfish server in debug mode and found out that "resource" was null. but @PostConstruct in singleton does print which means singleton bean exists.

      Can we call singleton beans with no interface in such a way form a session bean? I actually want to acquire instance of singleton bean when a client invokes method in Client bean