The EJB v. 3.1 Specification fills this gap defining, in its own words:
“a standardized global JNDI namespace and a series of related namespaces that map to the various scopes of a Java EE application.”
This blog post will give you an overview of the Global JNDI Access as defined by the EJB v. 3.1 Specification.
Namespaces and Scopes
The EJB v. 3.1 Specification defines three distinct namespaces with its own scopes:
The specification requires compliant containers to register all of the session beans with the required JNDI names. Such standardized names are portable and your application components will be able to establish a reference to an EJB using a name that is portable across application servers.
Names in the global namespace will be accessible to code in any application and conform to the following syntax:
<app-name> is the name of the Java EE application as specified in its standard deployment descriptor (application.xml) or, by default, the base name of the deployed EAR archive. This path fragment is used only if the session EJB is deployed within a Java EE application EAR file.
If the session EJB is deployed in an EAR file, its <module-name> is the path name of the Java EE module that contains the bean (without extension) inside the EAR file. If the session bean is deployed as a standalone Java EE component in a JAR file or as part of a Java EE web module in a WAR file (which is now allowed by the Java EE 6 Specification), the <module-name> is the name of the archive (without extension). The <module-name> value can be overridden by the <module-name> element of the component’s standard deployment descriptor (ejb-jar.xml or web.xml).
The <bean-name> is the EJB name as specified by the mechanisms described in the previous parts of this blog post.
The <interface-fqn> part is the fully qualified name of the EJB business interface.
The container has to register one JNDI global entry for every local and remote business interface implemented by the EJB and its no-interface view.
Session EJB With One Business Interface or a No-Interface View
If an EJB implements only one business interface or only has a no-interface view, the container is also required to register such a view with the following JNDI name:
Names in the application namespace will be accessible only to code within the same application and conform to the following syntax:
Each path fragment retains the same meaning described for the global namespace JNDI names syntax in the previous section.
The same publishing rules for a compliant container described in the previous section apply.
Names in the module namespace will be accessible only to code within the same module and conform to the following syntax:
Once more, each path fragment retains the same meaning described for the global namespace JNDI names.
The same publishing rules for a compliant container described in the global namespace section.
It may be important to notice that, although global JNDI names for local interfaces (and no-interface views) are published, this does not imply that such an interface will be accessible to components running in another JVM.
The EJB v. 3.1 Specification, and other specifications in the Java EE 6 Platform, brings simplicity and adds many new features and tools to the developers’ toolboxes. “Global JNDI names” is an outstanding, although simple, feature because it finally fills a long-standing portability limitation of the previous revisions of this specification and, hence, of the entire Java EE platform.
EJB 3.0 and EJB 3.1 provide a powerful, portable, yet simple component model to build enterprise applications. The “EJB sucks” day are gone but only time will tell if this technology will regain the trust of Us, The Developers.
As far as it concerns myself, I feel pretty comfortable with Java EE 6, EJBs, CDI beans, the good support I have from IDEs such as NetBeans or JDeveloper (although the latter does not support EJB 3.1 yet), and all the specifications that build up this venerable platform
Get ready to program in a whole new way!
Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.