A local client has these characteristics:
It must run in the same application as the enterprise bean it accesses.
It can be a web component or another enterprise bean.
To the local client, the location of the enterprise bean it accesses is not transparent.
The no-interface view of an enterprise bean is a local view. The public methods of the enterprise bean implementation class are exposed to local clients that access the no-interface view of the enterprise bean. Enterprise beans that use the no-interface view do not implement a business interface.
The local business interface defines the bean’s business and lifecycle methods. If the bean’s business interface is not decorated with @Local or @Remote, and the bean class does not specify the interface using @Local or @Remote, the business interface is by default a local interface.
To build an enterprise bean that allows only local access, you may, but are not required to do one of the following:
Create an enterprise bean implementation class that does not implement a business interface, indicating that the bean exposes a no-interface view to clients. For example:
@Session public class MyBean { ... }
Annotate the business interface of the enterprise bean as a @Local interface. For example:
@Local public interface InterfaceName { ... }
Specify the interface by decorating the bean class with @Local and specify the interface name. For example:
@Local(InterfaceName.class) public class BeanName implements InterfaceName { ... }
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.
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;
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");
Client access to enterprise beans that implement local business interfaces is accomplished using either dependency injection or JNDI lookup.
To obtain a reference to the local business interface of an enterprise bean through dependency injection, use the javax.ejb.EJB annotation and specify the enterprise bean's local business interface name.
@EJB Example example;
The obtain a reference to a local business interface of an enterprise bean using JNDI lookup, use the javax.naming.InitialContext interface's lookup method.
ExampleLocal example = (ExampleLocal) InitialContext.lookup("java:module/ExampleLocal");