I would like me to understand this area of ββthe EE specification well enough to give you a definitive answer, but I do not.
The JBoss EJB documentation has this to say:
- The @EJB annotation also has the mappedName () attribute. The specification leaves this vendor-specific metadata, but JBoss recognizes mappedName () as the global JNDI name of the EJB you are referring to. If you specified mappedName (), then all other attributes are ignored, and this global JNDI name is used for binding.
- If you specify @EJB without the attributes defined [...] then the following rules apply:
- The bean in the EJB byte searches for the EJB with the interface used to inject @EJB. If there is more than one EJB that publishes the same business interface, an exception is thrown. If there is only one bean with this interface, then this one is used.
- Search for EARs for EJBs that publish this interface. If there are duplicates, an exception is thrown. Otherwise, the corresponding bean is returned.
- Search globally in JBoss for the EJB of this interface. Again, if duplicates are thrown, an exception is thrown.
- @ EJB.beanName () matches. If beanName () is defined, then use the same algorithm as @EJB without attributes, except for using beanName () as the key in the search. An exception to this rule is the use of the syntax "#" ejb-link. The syntax "#" allows you to put the relative path in the bank in the EAR, where you refer to EJB to life. See the specification for more details.
"A worldwide search in JBoss for the EJB of this interface" certainly assumes that an injection like the one you wrote should work. Indeed, it should work without beanName . However, my suspicion is that, in terms of the component in the WAR, the component in the EJB-JAR is remote, and so you will need to use a remote interface.
So the first thing I will try:
@EJB private IUserFacadeRemote userFacade;
Without beanName , in case of problems. Looks like you tried this.
If the normal approach to injection does not work, I can return to trying to inject via mappedName , which in JBoss is the global JNDI name. So:
@EJB(mappedName = "java:global/Users-ejb/userFacade!facades.IUserFacadeRemote") private IUserFacadeRemote userFacade;
This is obviously pretty ugly.
Anyway, good luck!
EDIT . Something else you could try is to use a qualified relative beanName , which explicitly calls the EJB-JAR:
@EJB(beanName = "Users-ejb.jar#userFacade") private IUserFacadeRemote userFacade;
Since WAR and EJB-JARs are not packaged in EARs, this could be:
@EJB(beanName = "../Users-ejb.jar#userFacade") private IUserFacadeRemote userFacade;
But at this point, Iβm just guessing.
CHANGE BACK ARROWS . Perhaps we missed something very simple. The @EJB annotation lookup @EJB allows @EJB to specify "a portable search string containing the JNDI name for the target EJB component", therefore
@EJB(lookup = "java:global/Users-ejb/userFacade!facades.IUserFacadeRemote") private IUserFacadeRemote userFacade;
Can work. This is essentially a portable version of JBoss-specific use of mappedName .