3 Replies Latest reply on Sep 22, 2011 7:08 AM by b.eckenfels

    Why aren't my @Singletons instantiated?

    tluettgert

      Hi all,

       

      I'm currently migrating a JAX-RS application from glassfish 3.1 to JBoss 7.0.1. After a few minor pains, the .war deploys to both application servers, but alas, it only works in glassfish, because I have a few classes annotated with @Singleton which I expect to find in @Stateless instances, like this:

       

      @Singleton
      public class ENDALog {

           ...

      }

       

      @Stateless
      @Path("/session")
      public class SessionService {

           @EJB private ENDALog log;

       

           @GET

           @Produces("application/json")

           public Response getSession(@Context HttpHeaders headers) {

                ...

           }

      }

       

      ... and when getSession() is called, log == null.

       

      I have no idea how to fix this. Any help is greatly appreciated.

       

      Regards,

      Torsten

        • 1. Re: Why aren't my @Singletons instantiated?
          foumpie

          Singletons have to implement Serializable ?

          (AS 7 normally throws an error for that, so it would be odd if you missed it)

           

          And  btw, why not use @Inject ? @EJB is soo 2010

          • 2. Re: Why aren't my @Singletons instantiated?
            jaikiran

            foumpie wrote:

             

            Singletons have to implement Serializable ?

            (AS 7 normally throws an error for that, so it would be odd if you missed it)

             

            No, that's not an requirement and I haven't seen an error being thrown for that.

            • 3. Re: Why aren't my @Singletons instantiated?
              b.eckenfels

              What profile are you using? I currently use a MDB with a singleton reference, and this works. The Singleton is instanciated as soon as the MDB is instanciated (or beforeif I use the @Startup annotation on the singleton class).

               

              If problems occur while instanciating the Singleton or while resolving the reference they should actually be logged. It could only be that a deployer is missing and does not scan your artifacts correctly, so try the standalone-preview.xml profile.