1 Reply Latest reply on Jan 31, 2017 4:44 AM by wdfink

    Is it possible to make local JNDI lookup between different EARs on same Wildfly?

    oleggritsak

      Hello!

       

      Spent several days with no positive result. Maybe I'm trying to do something impossible? Please, enlighten me, dear sirs!

       

      I want to implement some sort of microservices with EJBs and it should work at full speed, so remote JNDI is unacceptable.

       

      I've make simplest EJB with annotations:

      @LocalBean
      @Singleton

       

      deployed it to Wildfly (tried 10.0 and 10.1), got JNDI names

       

      java:global/empService/EmployeemanagerBean!model.ejbs.EmployeemanagerBean
      java
      :app/empService/EmployeemanagerBean!model.ejbs.EmployeemanagerBean
      java
      :module/EmployeemanagerBean!model.ejbs.EmployeemanagerBean
      java
      :global/empService/EmployeemanagerBean
      java
      :app/empService/EmployeemanagerBean
      java
      :module/EmployeemanagerBean

       

      In second EJB I try to lookup with

       

      try {
        
      final Hashtable jndiProperties = new Hashtable();
         jndiProperties
      .put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        
      final Context context = new InitialContext(jndiProperties);
        
      EmployeemanagerBean sm = (EmployeemanagerBean) context.lookup("java:global/empService/EmployeemanagerBean!model.ejbs.EmployeemanagerBean");
         } catch (NamingException e) {
        
      System.out.println(e.toString());
        
      return;
      }

       

      but only get Class Cast Exceptions.

       

      java.lang.ClassCastException: model.ejbs.EmployeemanagerBean$$$view38 cannot be cast to model.ejbs.EmployeemanagerBean

       

      Am I doing something wrong? Does anybody use this?

        • 1. Re: Is it possible to make local JNDI lookup between different EARs on same Wildfly?
          wdfink

          So your ... provide only a local business interface?

          In this case the Local interface is only available inside of the same ear file (according to the spec it is optional to use a wider scope here and not implemented).

           

          You need to implement the Remote interface to be able to look it up from a different application ear/jar.

          With Wildfly the invocation is optimized by default and the invocation is "by reference" if you not set the configuration back to "call by value".