Session EJB and Servlet as Different EAR Modules, JNDI Lookup

From NovaOrdis Knowledge Base
Revision as of 18:08, 24 March 2017 by Ovidiu (talk | contribs) (Created page with "=Internal= * EJB Concepts - Invoking into EJBs =Overview= This example describes the injection of an @EJB reference and subsequent invoc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview

This example describes the injection of an @EJB reference and subsequent invocation, when the EJB and the calling component (a servlet, in this case) are part of the same WAR deployment artifact.

GitHub Example

https://github.com/NovaOrdis/playground/tree/master/jee/ejb/stateless-and-servlet-within-ear-jndi

Business Interface Type Access

The EJB code and the calling component code are part of the same deployment unit, so the calling component has implicit access to the business interface class. No special configuration is needed here.

EJB Lookup

The EJB reference is injected by the container upon encountering the @EJB annotation, no JNDI lookups are involved:

...
@EJB
private SimpleStateless bean;
...

EJB Invocation

Once the EJB reference is obtained from JNDI, business interface methods can be called on its reference:

...
bean.methodOne("something from servlet");