11 Replies Latest reply on May 25, 2011 12:03 PM by jaikiran

    Binding EJB's to JNDI

    prasad.deshpande

      Hi Guys,

       

      I know it would sound stupid, but I'm having a strange problem. I've an EAR which contains couple of WAR files & an ejb.jar file. I'm trying to deploy this on 6.1.0-snapshot, it gets deployed, but while deploying sometimes it throws error saying particular EJB is not bound to JNDI.

       

      Under normal behaviour I'd expect, when I deploy ear, EJB's gets deployed & bound to JNDI & then WAR files deployed to resolve EJB references by WAR's.

       

      In my case what happens is some ejb's gets deployed, then WAR files deployed & then remaining EJB's getting deployed. So WAR files can not find those ejb's resulting throwing error. Strange thing is, this happens only sometimes, not always. If I restart JBoss, there are very good chances that it will deploy correctly.

       

      Can anyone think of anything here which could be specific to JBoss 6? cause this gives no problem on 5.1.0.

       

      Thanks,

      Prasad

        • 1. Binding EJB's to JNDI
          wdfink

          I suppose it is because you use a snapshot.

          Could you reproduce it with a fresh downloaded 6.0.0-final version.

          • 2. Binding EJB's to JNDI
            prasad.deshpande

            I can't deploy my application on 6.0.0-final as it has some issues. One of them is https://issues.jboss.org/browse/JBAS-8895. So I only have chance to deploy on 6.1.0.

             

            Besides, though I'm using snapshot version, that sould not give such basic problems. Any thoughts?

            • 3. Re: Binding EJB's to JNDI
              jaikiran

              You'll have to post the relevant bean code and the relevant exception stacktrace(s).

              • 4. Re: Binding EJB's to JNDI
                prasad.deshpande

                I've attached boot.log here. You can clearly see

                 

                09:22:01,250 ERROR [STDERR] javax.ejb.EJBException: org.jboss.injection.manager.spi.InjectionException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: RuleManager not bound]]

                 

                It is complaining about RuleManager not being bound to JNDI at the time of deployment of WAR, and then a second later you see this in the following log.

                 

                09:22:02,640 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                 

                    efp/RuleManager/local - EJB3.x Default Local Business Interface

                    efp/RuleManager/local-com.banctec.caseware.server.rulemanager.RuleManagerLocal - EJB3.x Local Business Interface

                So surely here there is some timing issue.

                • 5. Re: Binding EJB's to JNDI
                  jaikiran

                  Like I said earlier:

                   

                  You'll have to post the relevant bean code

                  • 6. Re: Binding EJB's to JNDI
                    prasad.deshpande

                    Hope, this helps..

                    @Stateless(name="RuleManager", description="Rule Manager")

                    @TransactionAttribute(TransactionAttributeType.REQUIRED)

                    @Resources({

                        @javax.annotation.Resource(authenticationType=AuthenticationType.CONTAINER, type=TopicConnectionFactory.class, name="jms/TopicFactory", mappedName="java:/JmsXA"),

                        @javax.annotation.Resource(name="jms/AuditTopic", type=Topic.class, mappedName="topic/efpAuditTopic")

                    })

                    @Local(RuleManagerLocal.class)

                    public class RuleManagerBean implements RuleManagerLocal {

                         //method goes here

                    }

                    • 7. Re: Binding EJB's to JNDI
                      jaikiran

                      We'll also need the code of other bean(s) or other components (like servlets) which inject this RuleManagerBean.

                      • 8. Re: Binding EJB's to JNDI
                        prasad.deshpande

                        Hi Jaikiran,

                         

                        Sorry, due to security reasons, I can't give you all the code, but I'll try to paste the relavant code.

                         

                        Firstly abstract class PC:

                        public abstract class PC {

                              // Other injected beans

                         

                            @EJB

                            @IgnoreDependency

                            private RuleManagerLocal ruleManager;

                         

                             //other methods

                         

                        protected RuleManagerLocal getRuleManagerLocal() throws CaseWareException {

                                if (ruleManager == null) {

                                  //createRuleManager will lookup in JNDI for Local Interface

                                    ruleManager = ServiceLocator.getInstance().createRuleManager();

                                }

                                return ruleManager;

                            }

                        }

                        }

                         

                        APCBean:

                         

                        @Stateless(name="APC", mappedName="caseware/APC")

                        @TransactionAttribute(TransactionAttributeType.REQUIRED)

                        @Remote(APC.class)

                        public class APCBean extends PC implements APC {

                         

                        //all other business methods....

                         

                             public void doSessionCleanup() {

                                  //some code

                             }

                        }

                            

                        SessionCleanupImp class:

                        public class SessionCleanupImp {   

                             // other methods

                         

                            public void setup()  {        

                             //some other code

                                       try {

                                        Context mContext = new InitialContext();

                                        APC apc = (APC)mContext.lookup("caseware/APC");

                                       

                                        apc.doSessionCleanup();

                                        log("Cleanup done.");

                                       } catch (Exception e) {           

                                         e.printStackTrace();

                                       }

                                   }

                        }

                         

                        In a WAR file a Servlet calls this SessionCleanupImp.setup() method. which intern calls doSessionCleanup() business method on APCBean. I suspect, since this is the first business method being called on apc bean, that is the point where ejb injection happens, & because RuleManager is not yet bound to JNDI, it throws error.

                        • 9. Re: Binding EJB's to JNDI
                          jaikiran

                          Remove that @IgnoreDependency, that should get you past this (assuming that I'm reading your code correctly).

                          • 10. Re: Binding EJB's to JNDI
                            prasad.deshpande

                            tried that, still inconsistent, sometimes it works when bean is deployed before WAR. It still gives same error. BTW, what was the logic of removing @IgnoreDependency? what is happening behind the scenes here you reckon?

                            • 11. Re: Binding EJB's to JNDI
                              jaikiran

                              If you have a @IgnoreDependency, then the server will not setup the correct dependencies during deployment. That can result into issues like the one you are seeing.

                               

                              At this point, I can't much guess on what's wrong, unless I see the actual application or a simple one which reproduces it.