5 Replies Latest reply on Sep 2, 2010 10:00 AM by wdfink

    How to inject EJBs with custom injector?

    christian.strempfer
      I have a distributed environment and a service locator, which can  locate all EJBs on different servers. Is it possible to use the standard @EJB-Annotation, but  make the lookup on my own?

       

      For example:

      @javax.ejb.EJB(name = "ejb/TestService")
      private TestService testService;

      Should trigger:

      return ServiceLocator.findEJBService(TestService.class, "ejb/TestService")
      My intention is to keep the deployment transparent for the developers. They can use @EJB as normal, but will end up using the service locator.
        • 1. Re: How to inject EJBs with custom injector?
          jaikiran

          Christian, welcome to the forums.

          Christian Strempfer wrote:

           


          Should trigger:

          return ServiceLocator.findEJBService(TestService.class, "ejb/TestService")
          My intention is to keep the deployment transparent for the developers. They can use @EJB as normal, but will end up using the service locator.

          Isn't it already transparent? I mean each developer just has to do @EJB. That's it! I'm not sure I understand the rationale behind using the ServiceLocator.

          • 2. Re: How to inject EJBs with custom injector?
            christian.strempfer

            There are EJBs distributed across different servers, which have their own Java Naming Directories. Because of that I cannot define exactly one JNDI-URL for the lookup. The service locator is configured, so that it can determine the lookup URL.

            • 3. Re: How to inject EJBs with custom injector?
              wdfink

              I do not understand why you will spread EJBs accross different server.

              @EJB will be transparent.

              A individual lookup will increase the complexity. Also you might have problems with transaction handling.

              • 4. Re: How to inject EJBs with custom injector?
                christian.strempfer

                Thank you for your advice about transaction handling, but the deployment scenario is not up for discussion, it is a specified requirement. We have application components which may be deployed independently on different servers. Also there are components which need access to other components on more than one server.

                • 5. Re: How to inject EJBs with custom injector?
                  wdfink

                  No, this is special. If you want to decide which server you want to connect the only way IMHO is to code it.

                  One option is a @PostConstruct initializer will fill, another one can be a Interceptor and your own annotation.