users@ejb-spec.java.net

[ejb-spec users] Portable JNDI names comments

From: Samuel Santos <samaxes_at_gmail.com>
Date: Fri, 10 Feb 2012 01:34:05 +0000

Hi all,

I find the Global JNDI Namespace, and finally having portable names across
different containers, a really neat feature.
However, it still is not easy to inject EJB from different modules inside
an EAR archive.

I'm working on a small open source project [1] to support @EJB, @Inject and
@Resource standard Java EE annotations on Stripes Framework [2] using
portable JNDI names.
As you can see by looking at the code [1], I'm using
context.lookup("java:app/AppName") and
context.lookup("java:module/ModuleName") to build the JNDI names to lookup.

Unfortunately it only works as long as you are injecting EJBs inside the
same module where it is.
If you have an EAR with two modules, one WAR and one EJB, and try to inject
an EJB in a class inside the WAR, the code will not work.
We have to define the full JNDI name in the mappedName or lookup elements
of the @EJB annotation every time we are injecting a session bean in a
class inside the WAR archive.

I believe it is the role of the EJB spec to make this easier.
Can we define a way to configure projects to lookup for JNDI names in other
modules (e.g. by defining/enumerating them in web.xml or other deployment
descriptor)?

[1]
https://github.com/samaxes/stripes-injection-enricher/blob/master/src/main/java/com/samaxes/stripes/enricher/EJBInjectionEnricher.java
[2] http://www.stripesframework.org

Thanks and best regards,

--
Samuel Santos
http://www.samaxes.com/