1 Reply Latest reply on Nov 25, 2011 12:23 PM by André Simões

    EJB3 Injection

    André Simões Newbie



      Imagine the following scenario:


      One JBoss cluster with web apps

      Other JBoss cluster with Ejb, jms, etc..

      The clusters are isolated by a DMZ.


      From the web app cluster, I need to inject some EJB's from the other cluster.

      The only way (that I realize) to do it is with some code like this:


      static public TestFacade assfac(){
          if( Facade._assfac ==null ) {
              try {
                  Context ctx = new InitialContext(getProperties());
                  Facade._assfac =  (TestFacade) ctx.lookup("TestFacade/remote");
              } catch (Exception e) {
                  Facade._assfac = null;
          return Facade._assfac;
      //pass cluster urls for injection
      //Ex: facadeurls=","
      private static Properties getProperties() {
          String facadeurls = System.getProperty("FacadeUrls", ""); 
          Properties p = System.getProperties();
          if (facadeurls.length()> 1)    {//Got property on path
              p.put(Context.PROVIDER_URL, facadeurls);    
          return p;


      This approach works, but do not work well!


      1º It tends to always inject from the first ip found on properties.


      2º If jboss node from first ip is offline, it injects from the next ip, but if jboss fails after injection, we have to inject again or we receive a connection refused.


      There are some way to have some kind of load balancing/failure detection on ejb injection?


      Do someone sugests another way to solve this problem?



        • 1. Re: EJB3 Injection
          André Simões Newbie

          As usual, no reply...


          In this case the solution seems to be quite easy.


          For the ones that some day will gonna be stuck on something like this, just annotate your beans implementation with the annotation @Clustered


          This will garantee that a external client accessing to a remote interface of a bean, in a cluster, with got load balancing and failure detection.


          In other words, if your client has a url connection for and ip nodes are, Even if node shutdown, the client do not even notice!!!



          I do not know if this is the best implementation, but no one talks about this...