In this tutorial you will learn how to create an enterprise bean that will be allowed to access locally or remotely.
In this tutorial you will learn how to create an enterprise bean that will be allowed to access locally or remotely.In this tutorial you will learn how to create an enterprise bean that will be allowed to access locally or remotely.
If the business interface of bean is not defined with @Local or @Remote then by default the business interface is a local interface.
Creating enterprise bean to permit local access
An enterprise bean that permits only for the local access can be created by one of the following (optional) way :
@Local(InterfaceName.class) public class BeanName implements InterfaceName { ... }
How to locally access an enterprise bean
To achieve the no-interface view for locally accessing of an enterprise bean which is disclosed as a local, use either the dependency injection or JNDI lookup.
@EJB XYZBean xyzBean;
XYZBean xyzBean= (XYZBean) InitialContext.lookup("java:module/XYZBean");
To achieve locally accessing of an enterprise bean which implements the local business interfaces, use either the dependency injection or JNDI lookup.
@EJB XYZ xyz;
XYZLocal example = (XYZLocal) InitialContext.lookup("java:module/XYZLocal");
Creating enterprise bean to permit remote access
An enterprise bean that permits for the remote access can be created must either by :
@Remote public interface InterfaceName { ... }
@Remote(InterfaceName.class) public class BeanName implements InterfaceName { ... }
How to remotely access an enterprise bean
To achieve the accessing a client to an enterprise bean which implements the remote business interface, use either the dependency injection or JNDI lookup.
@EJB Example example;
ExampleRemote example = (ExampleRemote) InitialContext.lookup("java:global/myApp/ExampleRemote");
Ads