11 Replies Latest reply on Jul 13, 2012 2:47 AM by jaikiran pai

    EJB instance is null

    Chaitanya Kulkarni Newbie

      Trying to access ejb deployed. I was getting javax.naming.namenotfound exception.

      I added @EJB(mappedName=jndiname) in the interface class, however the EJB instance is returning null.

      I tried to use  @EJB(lookup=jndiname), however I get the attribute lookup is undefined for the annotation type EJB.

      Also to add  I am migrating my app from JBOSS 6 to JBOSS 7.

      Things work fine in JBoss 6.

      In JBoss 7 from log I am sure that ejbs are getting deployed. I have updated the appropriate jndi names(got those from server.log) in lookup.

      I am having issues while looking up ejb local interface

      Any help would be highly appreciated.

       

      Thanks

        • 1. Re: EJB instance is null
          Jay SenSharma Master

          Hi,

           

              What is the JNDI name which you are trying to lookup? using @EJB annotation

           

          Please refer to the following link for an example of  @EJB(lookup="something")

          http://middlewaremagic.com/jboss/?p=813

           

          And

           

          Invoking a Local Stateless Bean from a Servlet in JBoss AS7   http://middlewaremagic.com/jboss/?p=822

           

           

             NameNotFound will occur if you will enter a wrong lookup name , Please refer to the following link to know about the EE6 specific portable JNDI  Names:  http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html

          • 2. Re: EJB instance is null
            Wolf-Dieter Fink Master

            Could you provide a bit more informations?

            Use

                 @EJB(lookup="XXX") MyInterface bean;

            to inject in your application code.

            If the MyInterface is unique @EJB might be enough.

            • 3. Re: EJB instance is null
              Chaitanya Kulkarni Newbie

              Hi Jay Kumar,

              I am trying to invoke Stateless Bean from an interface.

              The Bean is deployed I see in the server log:

              JNDI bindings for session bean named stack_configuration in deployment unit subdeployment "web-controller-common-ejb-1.1.22-SNAPSHOT.jar" of deployment "web-controller-ear-1.1.22-SNAPSHOT.ear" are as follows:

               

               

                        java:global/web-controller-ear-1.1.22-SNAPSHOT/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal

                        java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal

                        java:module/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal

                        java:global/web-controller-ear-1.1.22-SNAPSHOT/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration

                        java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration

                        java:module/stack_configuration

               

              In the interface I am using JNDI name as :

                java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal.

               

              However I don't see any definition for lookup property in EJB.

              • 4. Re: EJB instance is null
                Wolf-Dieter Fink Master

                Chaitanya Kulkarni wrote:

                 

                I am trying to invoke Stateless Bean from an interface.

                 

                In the interface I am using JNDI name as :

                  java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal.

                 

                A interface can not invoke something.

                The lookup name should be ejb:app//web-controller-common-ejb-1.1.22-SNAPSHOT//stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal

                 

                You will find examples in the documentation:

                https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

                https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance

                • 5. Re: EJB instance is null
                  Chaitanya Kulkarni Newbie

                  Hi Wolf-Dieter Fink,

                  The Bean Class looks as following:

                  @Stateless(name = JndiConstants.STACK_CONFIGURATION, mappedName = JndiConstants.STACK_CONFIGURATION)

                  @Local(StackConfigurationLocal.class)

                  @LocalBinding(jndiBinding = JndiConstants.STACK_CONFIGURATION_LOCAL)

                  public class StackConfigurationEjb implements StackConfigurationLocal {

                  ...code...

                  }

                   

                   

                  In the interface I had following code:

                  private StackConfigurationLocal stackConfigurationLocal;

                     

                            public StackConfigurationProvider() {

                                      try {

                                                InitialContext initialContext = new InitialContext();

                   

                                                stackConfigurationLocal = (StackConfigurationLocal) initialContext.lookup(JndiConstants.STACK_CONFIGURATION_LOCAL);

                                                logger.debug("site_controller ejb references are acquired");

                                      } catch (Exception fatal) {

                                                logger.error("Couldnot bind web controller interface "+JndiConstants.STACK_CONFIGURATION_LOCAL, fatal);

                                      }

                            }

                   

                  Referring to the changes required I changed it to :

                  @EJB(mappedName=JndiConstants.STACK_CONFIGURATION_LOCAL)

                            private StackConfigurationLocal stackConfigurationLocal;

                   

                   

                   

                   

                            public StackConfigurationProvider() {

                                      try {

                                                InitialContext initialContext = new InitialContext();

                                          if(stackConfigurationLocal==null)

                                          {

                                                    logger.info("site_controller ejb references is null");

                                          }else

                                          {

                                                    logger.info("site_controller ejb references are acquired");

                                          }

                                          

                                                //stackConfigurationLocal = (StackConfigurationLocal) initialContext.lookup(JndiConstants.STACK_CONFIGURATION_LOCAL);

                   

                                      } catch (Exception fatal) {

                                                logger.error("Couldnot bind web controller interface "+JndiConstants.STACK_CONFIGURATION_LOCAL, fatal);

                                      }

                            }

                  =========================================

                  I see in the logs that ejb reference is null.  I used mappedName as I could not find lookup property.

                  Thanks

                  • 6. Re: EJB instance is null
                    Chaitanya Kulkarni Newbie

                    I changes the Jndiname to java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal.

                    However I am getting the nullpointerexception when calling a method on it.  So the reference is still null.

                    Also currently I am using the local interface.

                    Also the log says:

                    Exception sending context initialized event to listener instance of class : xxx java.lang.NullPointerException.

                    Thanks

                    • 7. Re: EJB instance is null
                      Wolf-Dieter Fink Master

                      @Stateless(mappedNmae=...)

                      will be ignored in AS7.

                       

                      If you use a local reference in the same container a simple @EJB annotation should be work.

                       

                      Also please read the documentation from my links above, the naming and lookup process in AS7 will be different to former version.

                      • 8. Re: EJB instance is null
                        Chaitanya Kulkarni Newbie

                        This is how my EJB Class looks like:

                        @Stateless

                        public class StackConfigurationEjb implements StackConfigurationLocal {

                        ...code...

                        }

                         

                        In the integration part I am using following code:

                        public class StackConfigurationProvider implements IConfigurationListener {

                         

                                  private Logger logger = LoggerFactory.getLogger(StackConfigurationProvider.class);

                         

                                  @EJB

                                  private StackConfigurationLocal stackConfigurationLocal;

                        ...code...

                         

                        }

                         

                        these two classes are in the same ear file.

                        Below is the log i get from server.log:

                        ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/chi]] (MSC service thread 1-5) Exception sending context initialized event to listener instance of cla

                        s com.hsl.chi.webapp.ChiLoader: java.lang.NullPointerException

                           at com.videobet.gis.webcontroller.integration.StackConfigurationProvider.getConfigurationProperty(StackConfigurationProvider.java:40) [web-controller-1.1.22-SNAPSHOT.jar:]

                           at com.hsl.chi.webapp.ChiLoader.contextInitialized(ChiLoader.java:368) [classes:]

                           at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                           at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                           at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

                           at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)

                           at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)

                           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_33]

                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_33]

                           at java.lang.Thread.run(Thread.java:662) [:1.6.0_33]

                         

                        I did go though documents and discussions tried to change jndi to java: from ejb: and vice versa.

                        However it did not help.

                        Any help would be highly appreciated.

                        Thanks again.

                        • 9. Re: EJB instance is null
                          Wolf-Dieter Fink Master

                          Where this code is deployed? Can you post how the classes are packed and where you use it?

                          • 10. Re: EJB instance is null
                            Chaitanya Kulkarni Newbie

                            The code is deployed in jboss\standalone\deployments. I am using Jboss 7.1

                            + site-controller-ear-1.1.22-SNAPSHOT.ear

                              + lib

                              - META-INF

                                  - jboss-deployment-structure.xml

                                  - application.xml

                                  - persistence.xml

                                  - MANIFEST.MF

                                  - jboss-app.xml 

                               - sg.webapp.jboss-1.0.0.war

                               - persistence-1.0.0.jar

                               - pkiguiwebapp.war

                               - pkiwebapp.war

                               - site-controller-1.2.22-SNAPSHOT.jar

                               - site-controller-common-ejb-1.2.22-SNAPSHOT.jar

                               - site-controller-web1.0.   

                             

                            EJBs are in

                            site-controller-1.2.22-SNAPSHOT.jar, site-controller-common-ejb-1.2.22-SNAPSHOT.jar. The particular one we are discussing is in site-controller-common-ejb-1.2.22-SNAPSHOT.jar and classes in sg.webapp.jboss-1.0.0.war call integration class StackConfigurationProvider  (code in previous reply) which is in site-controller-1.2.22-SNAPSHOT.jar and while calling the method on it nullpointerexception is generated.

                            Thanks.

                            • 11. Re: EJB instance is null
                              jaikiran pai Master

                              ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/chi]] (MSC service thread 1-5) Exception sending context initialized event to listener instance of cla

                              s com.hsl.chi.webapp.ChiLoader: java.lang.NullPointerException

                                 at com.videobet.gis.webcontroller.integration.StackConfigurationProvider.getConfigurationProperty(StackConfigurationProvider.java:40) [web-controller-1.1.22-SNAPSHOT.jar:]

                                 at com.hsl.chi.webapp.ChiLoader.contextInitialized(ChiLoader.java:368) [classes:]

                               

                              What does that ChiLoader class code look like? I'm guessing you are not looking up the bean in that class and instead are perhaps instantiating using the StackConfigurationProvider using the new operator?