Session EJB and Servlet as Different EAR Modules, @EJB Injection: Difference between revisions
(Created page with "=Internal= * EJB Concepts - Invoking into EJBs =Overview= This example describes the look up of an EJB and subsequent invocation, when t...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
This example describes the | 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 deployed in different modules, but part of the same EAR. | ||
=GitHub Example= | =GitHub Example= | ||
Line 24: | Line 24: | ||
=EJB Lookup= | =EJB Lookup= | ||
The EJB reference is | The EJB reference is injected by the container upon encountering the @EJB annotation, no JNDI lookups are involved: | ||
<pre> | <pre> | ||
... | ... | ||
@EJB | |||
private SimpleStateless bean; | |||
... | |||
</pre> | </pre> | ||
Latest revision as of 18:42, 24 March 2017
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 deployed in different modules, but part of the same EAR.
GitHub Example
Business Interface Type Access
The EJB code and the calling servlet component are deployed as part of two different EAR modules, so visibility of types amongst those two modules is subject to EAR module isolation configuration in the application server. In EAP 7, the modules are NOT isolated by default, so they have type visibility into each other. No special configuration is necessary for the example to work.
EAR sub-deployment isolation can be changed at the application server level, or per deployment in jboss-deployment-structure.xml.
More details on JEE module isolation in JBoss are available here:
- ee Subsystem Configuration - ear-subdeployments-isolated
- WildFly Modules - EAR Deployments
- jboss-deployment-structure.xml
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");