8 Replies Latest reply on Jan 17, 2011 5:02 AM by Snake Zori

    Can't inject EJB from external project

    Snake Zori Newbie

      I have some strange problems with injecting EJBs.


      Environment:
      Weblogic 10.3.3.0
      Seam 2.2.GA
      Richfaces 3.3.3.Final


      Projects are mavenized and the structure is:

      \ear\

      \ejb\

      \web\

      pom.xml


      there is also JPA project that is one of the dependecies.


      So, if I have some seam component (class annotated with @Name) that is in WEB project, like:




      @Name("homeMB")
      @Scope(ScopeType.PAGE)
      public class HomeMB implements Serializable {
      
          private static final long serialVersionUID = 1L;
          @Logger
          Log log;
      
          @In(create = true, required = true)
          UsersDAO usersDAO;
      
          @Create
          public void init(){
              log.info(HomeMB.class.getSimpleName() + "..... init() method .....");
              log.info(usersDAO.getUsers());
          }
      


      The UsersDAO is EJB that is in the EJB project. Now I get this error:


      Caused by: java.lang.NullPointerException
           at my.project.HomeMB.init(HomeMB.java:30)



      Line 30 is :


      log.info(usersDAO.getUsers());



      I can't see on Weblogic console output any sign of my EJB starting. HomeMB starts fine, though.



      In components.xml I have:




      <core:init debug="true" jndi-pattern="my-project-ear/#{ejbName}/local"/>



      Is this ok? My maven projects have version number in name, does it matter?


      My parent pom.xml has:




      <properties>
           <applicationVersion>0.0.11</applicationVersion>
               <seam.version>2.2.0.GA</seam.version>
      </properties>
      



      so my ear, war and jar has ie name: my-project-ejb-0.0.11.jar



      I can access  seam component fields from JSF - that works but I can't inject EJB from ejb-project.


      Thanks in advance


        • 1. Re: Can't inject EJB from external project
          Snake Zori Newbie

          I tried on JBoss 5.1 - same issue - so is it some xml-configuration problem?

          • 2. Re: Can't inject EJB from external project
            Snake Zori Newbie

            I have tried all tips from Seam documentation, posts found on this forum - with no luck.
            Anyone has (could share) a working copy of example Seam 2.2 project that deploys and works on Weblogic 10.3?


            • 3. Re: Can't inject EJB from external project
              Sakari Isoniemi Newbie

              Check if the NPE comes from Logger or DAO.


              if log is null, then app. class is not instantiated
              by Seam.

              • 4. Re: Can't inject EJB from external project
                Marcel Kiel Newbie

                If the EAR includes the version, the JNDI pattern must include it, too. My main pom.xml includes something like this:


                <properties>
                     <app.jndi.pattern>${ear.name}/#{ejbName}/local</app.jndi.pattern>
                     <ear.name>my-project-${project.version}</ear.name>
                     ...
                </properties>
                



                EAR pom.xml:


                <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-ear-plugin</artifactId>
                     <configuration>
                          <finalName>${ear.name}</finalName>
                ...
                



                components.xml:


                <core:init debug="${app.debug}" jndi-pattern="${app.jndi.pattern}" />
                



                This allows to easily change the EAR name, e.g. to include a deployment ID enabling you to run multiple deployments in parallel.


                But of course, the EJB has to be deployed correctly in any case. When using JBoss, you should see something like this at application startup:


                19:46:25,355 INFO  [SessionSpecContainer] Starting jboss.j2ee:ear=my-project-1.0.ear,jar=my-project-1.0-ejb.jar,name=UserDAOImpl,service=EJB3
                19:46:25,355 INFO  [EJBContainer] STARTED EJB: UserDAOImpl ejbName: UserDAOImpl
                19:46:25,366 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
                
                     my-project-1.0/UserDAOImpl/local - EJB3.x Default Local Business Interface
                     my-project-1.0/UserDAOImpl/local- UserDAO - EJB3.x Local Business Interface
                



                Oh and, just as a good habit, you should use parameters for logging - string concatenation is expensive, but would be executed even if you disable this log level:


                log.info("#0 ..... init() method .....", HomeMB.class.getSimpleName());
                

                • 5. Re: Can't inject EJB from external project
                  Snake Zori Newbie

                  Thanks for tips Marcel, however please correct me if I'm wrong:


                  in my scenario i MUST NOT have :




                      <ejb-local-ref>
                          <ejb-ref-name>ejb/UsersDAOBean/local</ejb-ref-name>
                          <ejb-ref-type>Session</ejb-ref-type>
                          <local>my.app.module.UsersDAO</local>
                      </ejb-local-ref>
                  




                  cause my jndi pattern dffers from version to version, right? Or should I put ${app.version}  into ejb-ref-name?


                  Does Weblogic 10.3.3.0 really needs it in web.xml?


                  Unfortunately I still can't run my example, message on console:




                  Could not instantiate Seam component: homeMB
                  ...
                  Caused by: java.lang.NullPointerException
                          at my.priject.module.HomeMB.init(HomeMB.java:30)
                  



                  here is my EJB:




                  @Stateless
                  @Name(UsersDAO.NAME)
                  public class UsersDAOBean implements UsersDAO {
                  
                      private static final long serialVersionUID = 5855999111119720298L;
                  
                      @Logger
                      Log log;
                  
                      @Create
                      @Override
                      public void init(){
                          log.info("#0 ..... Inside init() method .....", UsersDAOBean.class.getSimpleName());
                      }
                  
                  
                      @Override
                      public List getUsers() {
                          log.info("# ..... listing users here .....", UsersDAOBean.class.getSimpleName());
                          for(int i = 0; i < 10; i++){
                              log.info("#0 #1", UsersDAOBean.class.getSimpleName(), i);
                          }
                          return null;
                      }
                  }
                  


                  where @Name(UsersDAO.NAME) is defined in interface:



                  @Local
                  public interface UsersDAO extends Serializable {
                      public static final String NAME = "usersDAO";     
                      public List getUsers();
                      public void init();
                  }
                  



                  Hope You could push me with this further ;)



                  • 6. Re: Can't inject EJB from external project
                    Marcel Kiel Newbie

                    Well, I dont' know anything about WebLogic, but I assume you don't need <ejb-local-ref> at all if you use EJB3 annotations.


                    Did you have any luck testing the app in JBoss AS? Do the application startup log entries I mentioned show up there?


                    Another solution would of course be to set the EAR name to something static, not including the version. Just set the <finalName> in the pom.xml as described above.

                    • 7. Re: Can't inject EJB from external project
                      Alexandr Areshchanka Newbie

                      First check your logs, you should see that Seam instantiated EJB's from your ejb module.
                      Second check if seam.properties file is located in ejb module, because of if not then Seam will ignore it.

                      • 8. Re: Can't inject EJB from external project
                        Snake Zori Newbie

                        gosh.... you were absolutely right :( lame me ! seam.properties was mispelled! works now. I'll try to play with it (add JPA and stuff) and if it works I think I'll publish maven sources here for everyone to reuse.