The Java EE 6 Tutorial, Volume I

Remote Clients

A remote client of an enterprise bean has the following traits:

To create an enterprise bean that allows remote access, you must do one of the following:

The remote interface defines the business and life cycle methods that are specific to the bean. For example, the remote interface of a bean named BankAccountBean might have business methods named deposit and credit. Figure 14–1 shows how the interface controls the client’s view of an enterprise bean.

Figure 14–1 Interfaces for an Enterprise Bean with Remote Access

Diagram showing a remote client accessing an enterprise
bean's methods through its remote interface.

Accessing Remote Enterprise Beans

Client access to an enterprise bean that implements a remote business interface is accomplished using either dependency injection or JNDI lookup.


Example 14–6 Injecting an Enterprise Bean's Remote Business Interface

To obtain a reference to the remote business interface of an enterprise bean through dependency injection, use the javax.ejb.EJB annotation and specify the enterprise bean's remote business interface name.

@EJB
Example example;


Example 14–7 Looking Up an Enterprise Bean's Remote Business Interface

The obtain a reference to a remote business interface of an enterprise bean using JNDI lookup, use the javax.naming.InitialContext interface's lookup method.

ExampleRemote example = (ExampleRemote)
        InitialContext.lookup("java:global/myApp/ExampleRemote");