1 Reply Latest reply on Apr 28, 2017 1:43 PM by thomasgo

    Specialize EJB injection

    thomasgo

      Hi, is there an easy way to specialize injection of local EJBs?

       

      What I'm trying to achieve:

       

      We have a library that provides several business interfaces and implementations of those.

      That library is used by several projects and there is a huge number of injection points for a certain business interface.

       

      Now we have a situation where the project provides its own implementation of that interface which should entirely replace the implementation provided by the library.

       

      We can't just remove the library's implementation because other projects need to use it and we can't split the library because in future there might be other EJBs that need the same type of replacement and splitting libraries in order to no bundle those default implementations would end in a huge amount of one-class libraries.

       

      Thus we'd like to either tell JBoss/Wildfly to ignore a certain EJB or to use a special one whenever an implementation of an interface should be injected.

       

      I know that I could use ejb-jar.xml to override annotations and tell the container to inject a special implementation of an interface but AFAIK that would require me to list every single injection point so that would not be a preferred option.

       

      To illustrate the problem, consider the following (annotations partially omitted for simplicity):

       

      In the library:

      interface Business {}
      
      @Stateless
      class BaseEjb implements Business{}
      
      @Stateless
      class AnotherEjb {
        @EJB Business b;
      }
      

       

      In the project:

      @Stateless
      class ProjectEjb implements Business {}
      
      @Stateless
      class AnotherProjectEjb {
         @EJB Business b;
      }
      

       

      As you can see, there are multiple injection points for the interface Business. The library provides an implementation of the interface and the project provides one as well.

      There are also other EJBs which need to use Business but should use the same implementation, i.e. in the case above ProjectEjb should always be injected into AnotherEjb/b and AnotherProjectEjb/b.

       

      Is there a way to achieve this?

       

      We're currently running on JBoss 7.2.0 and would prefer not to upgrade yet, but when upgrading to Wildfly would be the only way to get this done then we'd consider that.


      Thanks in advance.