2 Replies Latest reply on Aug 7, 2015 6:17 AM by bshorty

    JNDI lookup problems

    bshorty

      Hi,

       

      I have a couple of issues relating to JNDI lookups I am currently trying to resolve and would be most grateful for any expert input on (disclaimer: I am fairly new to EJBs / J2EE).

       

      Setup:


      Using Wildfly-9.0.0.Final, Java 8, Spring-4.1.6


      App structure:

        my_application.ear

          | -- main-module.war

          | -- service-provider.jar


      First I have the following reference in jbossws-cxf.xml in main-module.war:

       

      <jee:local-slsb
        id="myEndpointEjb"
        jndi-name="java:global/my_application/my_ejb_module/MyEndpointEJB"
        business-interface="com.test.MyEndpointSPI"
        resource-ref="false" />
      
      
      
      
      
      
      
      

       

      with MyEndpointEJB being packaged in service-provider.jar. Most of the time this is fine, but in certain situations (it seems to be mostly on slower systems, e.g. running under a VM or docker container) the deployment will fail with javax.naming.NameNotFoundException trying to look up java:global/my_application/my_ejb_module/MyEndpointEJB.

       

      The logs show:

       

      (MSC service thread 1-1 ) -  - [as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor  ] INFO  - JNDI bindings for session bean named MyEndpointEJB in deployment unit subdeployment "service-provider.jar" of deployment "my_application.ear" are as follows:
      
        java:global/my_application/service-provider/MyEndpointEJB!com.test.MyEndpointSPI
        java:app/service-provider/MyEndpointEJB!com.test.MyEndpointSPI
        java:module/MyEndpointEJB!com.test.MyEndpointSPI
        java:global/my_application/service-provider/MyEndpointEJB
        java:app/service-provider/MyEndpointEJB
        java:module/MyEndpointEJB
      

       

      well before the deployment fails. Should that not mean those JNDI bindings are available from that point on? What sort of timing issue could be causing that behavior? (I want to avoid going down the road of using initialize-in-order in application.xml)

       

      The other issue is that I had hoped to avoid the dependency on the name of the ear file by switching to use java:app/service-provider/MyEndpointEJB as the JNDI reference instead, but doing this causes the deployment to consistently fail with the same error as above (i.e. it can't find that binding). What have I missed? I am trying to ascertain whether this is more a wildfly configuration issue or something to do with Spring.

       

      Any help would be most appreciated.

        • 1. Re: JNDI lookup problems
          jaikiran

          From what you state, it looks like there's a missing dependency between the Spring (web app) context and the EJB it's using. One way to fix this is to add a resource-ref entry in the web.xml of your .war to let the container know that it depends on the EJB so that the container can then properly bring up the dependencies in the right order.

           

          It would look something like this in the web.xml:

          <resource-ref>
              <res-ref-name>EndpointEJB</res-ref-name>       
              <lookup-name>java:global/my_application/my_ejb_module/MyEndpointEJB</lookup-name>
          </resource-ref>
          

           

          The logs show:

           

          1. (MSC service thread 1-1 ) -  - [as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor  ] INFO  - JNDI bindings for session bean named MyEndpointEJB in deployment unit subdeployment "service-provider.jar" of deployment "my_application.ear" are as follows: 
          2.  
          3.   java:global/my_application/service-provider/MyEndpointEJB!com.test.MyEndpointSPI 
          4.   java:app/service-provider/MyEndpointEJB!com.test.MyEndpointSPI 
          5.   java:module/MyEndpointEJB!com.test.MyEndpointSPI 
          6.   java:global/my_application/service-provider/MyEndpointEJB 
          7.   java:app/service-provider/MyEndpointEJB 
          8.   java:module/MyEndpointEJB 

           

          well before the deployment fails. Should that not mean those JNDI bindings are available from that point on?

           

          That doesn't guarantee the EJBs are bound at that point. It's just a informative log message stating that the EJBs will be availble at that JNDI names when the deployment succeeds.

           

          The other issue is that I had hoped to avoid the dependency on the name of the ear file by switching to use java:app/service-provider/MyEndpointEJB as the JNDI reference instead,

          In that case, just change the above snippet of web.xml, I posted, to use the java:app JNDI name java:app/service-provider/MyEndpointEJB. That should work.

           

          P.S: Although, it's not related to your issue, there's already a 9.0.1.Final released, you might want to use that one Downloads · WildFly

          • 2. Re: JNDI lookup problems
            bshorty

            Thanks very much for your reply, while attempting to resolve this I did in fact attempt to do exactly what you suggested but using the ejb-ref declaration, however neither that or resource-ref seemed to fix this issue for me.  Whether this is me missing something or an issue elsewhere I don't know.

             

            In the end I have worked around it by using the ejb namespace in the JNDI lookup instead (thus deferring initialisation), not ideal and it shouldn't be necessary - but for the moment that is what I will work with.

             

            Cheers.