4 Replies Latest reply on May 3, 2013 9:31 AM by jaikiran

    Problem with local EJB JNDI lookup

    hussain76

      Hi,

       

      I'm using JBoss AS 7.1.2.

       

      I've a local EJB as follows:

       

      @Local
      public interface IBenutzerServiceIntern {
      
      @Stateless
      public class BenutzerServiceIntern extends AbstrakterPersistenzService implements IBenutzerServiceIntern {}
      
      

       

      JBoss AS 7 tells me that the EJB is available under the following JNDI names:

      java:global/sd01_persistenz/sd.server.persistenz.impl/BenutzerServiceIntern!com.example.sd.persistenz.services.benutzer.IBenutzerServiceIntern
      java:app/sd.server.persistenz.impl/BenutzerServiceIntern!com.example.sd.persistenz.services.benutzer.IBenutzerServiceIntern
      java:module/BenutzerServiceIntern!com.example.sd.persistenz.services.benutzer.IBenutzerServiceIntern
      java:global/sd01_persistenz/sd.server.persistenz.impl/BenutzerServiceIntern
      java:app/sd.server.persistenz.impl/BenutzerServiceIntern
      java:module/BenutzerServiceIntern
      

       

      I try to perform a JNDI lookup within the same module as follows:

       

      public class Konverter {
       static {
        try {
         InitialContext.doLookup("java:module/BenutzerServiceIntern");
        } catch (final NamingException e) {
         e.printStackTrace();
        }
      }
      

       

      When this code is executed on server startup, I get the following error:

       

      When this code is executed, I get the following error:

      javax.naming.NameNotFoundException: java:module/BenutzerServiceIntern
       at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:127)
       at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
       at javax.naming.InitialContext.lookup(InitialContext.java:392)
       at javax.naming.InitialContext.doLookup(InitialContext.java:265)
       at com.example.sd.persistenz.konverter.Konverter.<clinit>(Konverter.java:51)
      
      

       

      Anybody got an idea why this fails?

        • 1. Re: Problem with local EJB JNDI lookup
          nickarls

          And you are sure the lookup happens post-deployment? Is it the same result with the other JNDI names?

          • 2. Re: Problem with local EJB JNDI lookup
            wdfink

            I'm not sure whether this will work.

            Is it not possible to use a non static approach and  injection?

            1 of 1 people found this helpful
            • 3. Re: Problem with local EJB JNDI lookup
              hussain76

              At least the given piece of code is executed after the server logs tell about the EJB's JNDI bindings (as written above). I also tried the other JNDI names given (java:global, ...), they also don't work.

               

              For testing purposes I've configured a datasource in standalone-full.xml and performed a JNDI lookup on the datasource in the above given static code block: this succeeds.

               

              Using injection is unfortunately not an option. Maybe I should try with a non-static approach.

              • 4. Re: Problem with local EJB JNDI lookup
                jaikiran

                That code won't work without proper dependencies. Injection is one way of implicitly adding a dependency. Is that a random class from where you are doing a lookup? Why not do that lookup from some container managed component like servlet, EJB etc...?