3 Replies Latest reply on Aug 13, 2009 12:31 AM by Greg Zoller

    Getting set up--Newbie

    Greg Zoller Newbie

      Hello,


      I'm trying to get my first hello world web beans app up and running.


      For the purposes of my test I have two EARs.  One is headless (no UI) and contains the web beans.  The other is a trivial Seam app that uses remote EJB calls to the first app to exercise the logic and present results to a browser.


      The key question here is that my web beans do not seem to be instantiating in the headless app.  Code here:


      package game;
      import javax.context.ApplicationScoped;
      @ApplicationScoped
      public class Foo {
           public int getNum() {
                return 5;
           }
      }
      



      and the code living in the same EAR that's trying to create/inject a Foo instance:


      import javax.ejb.*;
      import game.*;
      import javax.inject.Current;
      
      @Stateless
      public class RegistryManager implements RegistryService { // remote interface
           @Current Foo foo;
      
           // This is a method exposed in the remote interface, called by the Seam app.
           // It is successfully called, but I get the "foo is null" message.
           public String blah() {
                if( foo == null )
                     return "foo is null";
                else
                     return "Foo's num is: "+foo.getNum();
           }
      }
      



      What am I doing wrong that a Foo object is not being created/injected?  I'm running JBoss 5.1.0.GA out of the box.


      Thanks!
      Greg

        • 1. Re: Getting set up--Newbie
          Greg Zoller Newbie

          Ok, I tried something slightly different but still no dice.


          Trying to piece together what I'm understanding from the documentation, the Web Beans Manager can't do its injection magic on objects creating with new(), which I presume would include my EJBs created by the container, not the Manager.


          So something has to bootstrap the whole graph of dependencies and injection, right?  How is this done?


          Another poster talked about getting an instance of CurrentManager and use it to create a web beans instance.  Presumably once a web bean is created by the Manager we're off to the races, as all other dependencies would be created/injected by the Manager.


          So I tried this:


          Manager manager = CurrentManager.rootManager();
          if( manager == null )
               System.out.println("!!!!!!!!! Null manager");
          else
               masterRegistry = (Foo) manager.getInstanceByName("Foo");
          



          Unfortunately this produced a null Manager instance.


          How can I bootstrap this thing so my injections will work?  If this code is correct, and the approach ok, then is the likely problem in the out-of-the-box JBoss 5.1.0 installation?  I did have to copy the file webbeans-core.jar into JBoss' deployers/webbeans.deployer directory for the build path to pick up on CurrentManager.  (This directory is missing a lot of files present in the webbeans preview lib dir--is that important?)


          Thanks,
          Greg

          • 2. Re: Getting set up--Newbie
            Nicklas Karlsson Master

            And you have the beans.xml file present? Do you see the beans boot up in the log?


            You might want to do ant update in the jboss-as dir of Web Beans. Unless the deployer is still broken ;-) Check with Pete

            • 3. Re: Getting set up--Newbie
              Greg Zoller Newbie

              Ahh...That was it.  Putting a beans.xml in my META-INF directory caused the server to attempt to load the beans.  Thank you!


              I'm now past this problem and on to the next. :-)