1 Reply Latest reply on Jun 13, 2016 3:19 PM by mrts.pydev

    Using @Remote EJBs across artifacts deployed inside the same application server

    mrts.pydev

      Hello!

       

      I’m using WildFly 9 and I would like to use inter-artifact communication between artifacts (WARs, EJB JARs, EARs) deployed inside the same application server as easily as possible. EJB 3.1 spec brought many simplifications; I wonder if it is possible to simply use the @EJB annotation to inject remote beans into objects that need to communicate across artifact boundaries? If not, what’s the most straightforward way to achieve this?

       

      Here’s a concrete scenario:

       

      I have a web application packaged as a WAR that needs to use a service from a large monolithic application that is packaged as an EAR. I expect to annotate the service interface with @Remote, extract it into a separate API JAR and reference the API JAR from both the WAR and EAR projects. Then I expect to implement the service in the EAR and inject it (using the interface) with the @EJB annotation as an instance field into a servlet in the WAR.

       

      I published a simplified project skeleton to GitHub as it is much easier to express this in code, see
      https://github.com/mrts/remote-ejb-injection .

       

      It’s a Maven project with the following modules:

       

      Build it with `mvn package` and deploy `service-ejb-impl/target/service-ejb-impl-1.0-SNAPSHOT.jar` and `service-client/target/service-client-1.0-SNAPSHOT.war` to WildFly to run it.

       

      I did purposefully not package the EJB JAR into an EAR as I would prefer to use the simplest solution possible – or is an EAR required?

       

      Currently WAR deployment fails with the following exception:

       

      org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'ee.mrts.service.HelloService' for binding ee.mrts.servlet.HelloServlet/helloService

       

      What needs to be changed to make it work?

      Thanks in advance,
      Mart

        • 1. Re: Using @Remote EJBs across artifacts deployed inside the same application server
          mrts.pydev

          I packaged the EJB into an EAR and got it to work. It seems the only way is to specify the full EAR name, module name, bean class and fully qualified remote interface name in the @EJB annotation lookup attribute as follows:

           

          @EJB(lookup = "java:global/service-ear/service-ejb-impl/HelloServiceImpl!ee.mrts.service.HelloService")

           

          Can I use configuration to avoid hardwiring this so that I can simply use the @EJB annotation without specifying the lookup attribute?

          Is there a way to avoid packaging the EJB into an EAR?