The Java EE 6 Tutorial, Volume I

Accessing Local Enterprise Beans Using the No-Interface View

Client access to an enterprise bean that exposes a local, no-interface view is accomplished either through dependency injection or JNDI lookup.

Clients do not use the new operator to obtain a new instance of an enterprise bean that uses a no-interface view.


Example 14–2 Injecting an Enterprise Bean Using the No-Interface View

To obtain a reference to the no-interface view of an enterprise bean through dependency injection, use the javax.ejb.EJB annotation and specify the enterprise bean's implementation class.

@EJB
ExampleBean exampleBean;


Example 14–3 Looking Up an Enterprise Bean Using the No-Interface View

To obtain a reference to the no-interface view of an enterprise bean using JNDI lookup, use the javax.naming.InitialContext interface's lookup method.

ExampleBean exampleBean = (ExampleBean) 
        InitialContext.lookup("java:module/ExampleBean");