How to inject remote EJBs using @EJB annotations
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
@EJBannotation, for example:
@EJB(lookup = "ejb:myear/mymodule/distinctname/MyEjb!com.example.MyEjbRemote")
private OdrPersistenceRemote bean;
- The only caveat is that all the client configuration needs to be done in the other files, since users can not pass additional parameters from the code. See How to configure an EJB client in JBoss EAP 6 / Client in EAP 6 calling an EJB remote interface on EAP 6 / Option 1 - Configuring remote servers in the JBoss profile
SBR
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.