How to inject remote EJBs using @EJB annotations

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Issue

  • In the case of EJBs deployed on separate instances of EAP is it possible to establish a reference using annotations, irather than old-fashioned JNDI way using the InitialContext class?
  • We are referencing EJB deployed in different EAR using Local interface. We have to different modules deployed seperately, packaged as EARs. One of the modules needs to inject an EJB from the other module. So far we can only get this working by referencing the remote interface of the EJB using the @EJB annotation with the mappedname attribute set. Is this the intended approach, or is there an approach we are missing for how to do this.

Resolution

  • Users can inject remote EJBs directly with @EJB annotation, for example:
  @EJB(lookup = "ejb:myear/mymodule/distinctname/MyEjb!com.example.MyEjbRemote")
  private OdrPersistenceRemote bean;
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.